2014-03-07 32 views
7

在我的csproj文件中,我定義它用於在指定的DLL來執行的xUnit測試的測試目標:如何讓xUnit runner只執行特定類中的測試?

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

這工作得很好,但是我想可以指定只在某些測試類應該被執行。這可能嗎?

回答

9

您可以將xunit任務切換爲Exec任務,並運行XUnit控制檯運行程序xunit.console.clr4.exe。這有用於指定要運行的「特徵」的命令行選項。這些是可以通過使用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

+2

您還可以使用 - 方法參數採用了全法名稱例如: 'xunit.console.clr4.exe -method Namespace.ClassName.MethodName' –

+5

@aguafrommars,與V2發佈,它更加容易:'xunit.console.exe -class'Namespace.ClassName''。 – MEMark

相關問題