Live unit testing exclude tests

I know it is possible to exclude the whole test project(s) from Live Unit Testing by right clicking on the test project and selecting the "Live Unit Testing" context menu.

But in my solution I have some long running/resource intensive tests, which I would like to exclude. Is it possible to exclude individual tests?

2

2 Answers

Easiest method is right clicking on the method in the editor view and selecting Live Unit Testing and Exclude. Menu as seen in Visual Studio 2017

You can also do it programatically with attributes.

For xUnit: [Trait("Category", "SkipWhenLiveUnitTesting")]

For NUnit: [Category("SkipWhenLiveUnitTesting")]

For MSTest: [TestCategory("SkipWhenLiveUnitTesting")]

more info at Microsoft docs

2

Adding onto adsamcik's answer, here's how you can exclude an entire project (like an integration tests project) programmatically:

via .NET Core's csproj file:

// xunit <ItemGroup> <AssemblyAttribute Include="Xunit.AssemblyTrait"> <_Parameter1>Category</_Parameter1> <_Parameter2>SkipWhenLiveUnitTesting</_Parameter2> </AssemblyAttribute> </ItemGroup> // nunit <ItemGroup> <AssemblyAttribute Include="Nunit.Category"> <_Parameter1>SkipWhenLiveUnitTesting</_Parameter1> </AssemblyAttribute> </ItemGroup> // mstest <ItemGroup> <AssemblyAttribute Include="MSTest.TestCategory"> <_Parameter1>SkipWhenLiveUnitTesting</_Parameter1> </AssemblyAttribute> </ItemGroup> 

or via assemblyinfo.cs:

// xunit [assembly: AssemblyTrait("Category", "SkipWhenLiveUnitTesting")] // nunit [assembly: Category("SkipWhenLiveUnitTesting")] // mstest [assembly: TestCategory("SkipWhenLiveUnitTesting")] 

I figured out how to add the assembly attribute in .net core's csproj file via this SO answer. The attributes came from MS's documentation.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like