如何让xUnit runner只在特定的类中执行测试?

时间:2014-03-07 08:17:46

标签: msbuild xunit xunit.net

在我的csproj文件中,我定义了一个测试目标,用于在指定的DLL中执行xunit测试:

<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>

这样可以正常工作,但是我希望能够指定只执行某些类中的测试。这可能吗?

1 个答案:

答案 0 :(得分:9)

您可以为xunit任务切换Exec任务并运行XUnit控制台运行程序xunit.console.clr4.exe。这有命令行选项,用于指定&#39; traits&#39;跑步。这些是可以使用TraitAttribute

分配给测试的名称值对
    [Trait("TraitName", "TraitValue")]
    public void MyTest(){ /*..*/ }

来自控制台运行的使用测试:

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