Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let xUnit runner only execute tests in specific classes?

In my csproj file I've defined a test target which is used to execute xunit tests in a specified DLL:

<UsingTask AssemblyFile="..\packages\xunit.1.9.2\lib\net20\xunit.runner.msbuild.dll"     TaskName="Xunit.Runner.MSBuild.xunit" />
  <Target Name="Test">
    <xunit Assembly="bin\Debug\My.Project.dll" />
</Target>

This works fine, however I would like to be able to specify that only tests in certain classes should be executed. Is this possible?

like image 297
Simon K Avatar asked Mar 07 '14 08:03

Simon K


1 Answers

You could switch out the xunit task for an Exec task and run the XUnit console runner, xunit.console.clr4.exe. This has command line options for specifying 'traits' to run. These are name value pairs that can be assigned to tests by using the TraitAttribute:

    [Trait("TraitName", "TraitValue")]
    public void MyTest(){ /*..*/ }

From the usage test for the console runner:

Valid /trait "name=value" : only run tests with matching name/value traits : if specified more than once, acts as an OR operation /-trait "name=value" : do not run tests with matching name/value traits : if specified more than once, acts as an AND operation

like image 139
Josh Gallagher Avatar answered Oct 21 '22 21:10

Josh Gallagher