Simon K
Simon K

Reputation: 275

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?

Upvotes: 8

Views: 4875

Answers (1)

Josh Gallagher
Josh Gallagher

Reputation: 5329

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

Upvotes: 10

Related Questions