DEV Community

loading...
Cover image for Faster .NET CI/CD pipelines with test filters
Focused Labs

Faster .NET CI/CD pipelines with test filters

Ryan Taylor
Software Developer Extraordinaire at Focused Labs
Originally published at focusedlabs.io Updated on ・1 min read

Sluggish integration and delivery pipelines leave developers vulnerable to distraction. If your unit and integration tests live in one .csproj and run in both CI and CD, tune your pipeline stages to run only relevant tests.

The Tests

[Fact]
[Trait("Category","Unit")]
public async Task ThisTest_ShouldBeAUnitTest() 
{
   // Useful unit test
} 

[Fact]
[Trait("Category","Integration")]
public async Task WhenThisThingDoesX_ThatThingShouldDoY() 
{
   // Useful integration test
} 
Enter fullscreen mode Exit fullscreen mode

Tuning the Pipelines

To run only unit tests in CI:
dotnet test --filter Category=Unit

To run only integration tests in CD:
dotnet test --filter Category=Integration


Photo credit: Andrew Parnell

Discussion (1)

Collapse
jaimechavarriaga profile image
Jaime Chavarriaga

If you are using xUnit or NUnit, instead MSTest .Net Core, you may check...
docs.microsoft.com/en-us/dotnet/co...