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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With