Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Visual Studio Online VS Test Task to ignore certain nUnit test categories

I am having a hard time telling Visual Studio Online to ignore certain tests I do not want to run during VSO build. I have one set of tests in my test library I do not want them to run during the online build process. Those tests might will take an extremelly long time to complete, so I do not want them to be part of the tests that will execute during the build phase, so the build agent takes as few minutes as possible to complete the build. So, I can mark those test with an NUnit category like this

/// <summary>
///     This is a long running test
/// </summary>
[Test]
[Category("LongRunningTest")]
public void ObtainsTourInformationTest() {
...
}

This is a partial capture of my test task definition. I read somewhere I could use the Test filter criteria for this purpose but I haven't figure it out. Visual Studio Test Task definition

I am using the following NUnit packages

<package id="NUnit.Runners" version="2.6.4" />  
<package id="NUnit" version="2.6.4"/>
<package id="NUnitTestAdapter" version="2.0.0" /> 

So, basically, what I need to know is how to tel Visual Studio Online Test Task to ignore tests marked with NUnit Category Attribute.

like image 664
Alfredo A. Avatar asked Mar 03 '17 19:03

Alfredo A.


2 Answers

"TestCategory!=LongRunningTest"

Alternatively, if working online in Visual Studio, group the tests by Traits and select only those you want to run.

like image 133
Charlie Avatar answered Oct 26 '22 23:10

Charlie


The other way to approach this is to put all the long running tests in a separate project and then either:

  • Exclude that specific project (as I have done with Membership.Business.LibraryCS.IntegrationTests.dll in the example below)
  • Or use a standard naming convention for projects that solely contain long running tests and then exclude all of those projects (as I have done for any project with 'endtoend' in its name in the example below)

Here's a screen grab of how we have that set up in Azure DevOps:

enter image description here

We find this particularly effective for end-to-end tests that hit the local DB and so don't work on DevOps. Putting them in their own project is ideal in that scenario as the end-to-end test project can have a connection string to the test database, whereas not having that connection in any of the unit test projects ensures they aren't accidentally hitting the database.

like image 28
tomRedox Avatar answered Oct 26 '22 23:10

tomRedox