请参见下面的DOS命令:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe WindowsFormsApplication1.csproj /t:Test
.csproj文件如下所示:
<PropertyGroup>
<NUnit3-ToolPath>C:\Development\C#\UnitTests\UnitTests\packages\NUnit.ConsoleRunner.3.6.1\tools</NUnit3-ToolPath>
</PropertyGroup>
<Target Name="Test">
<NUnit3 ToolPath="$(NUnit3-ToolPath)" Assemblies="C:\Development\C#\UnitTests\WindowsFormsApplication1\bin\Debug\UnitTests.dll" OutputXmlFile="test-results.xml" />
</Target>
如果我从DOS命令中排除:
/t:Test
,则即使单元测试失败,构建也会成功。运行此命令时,如何确保运行单元测试:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe WindowsFormsApplication1.csproj
最佳答案
答案只是添加一个AfterTargets属性,如下所示:
<Target Name="Test" **AfterTargets="Build">**
<NUnit3 ToolPath="$(NUnit3-ToolPath)" Assemblies="C:\Development\C#\UnitTests\WindowsFormsApplication1\bin\Debug\UnitTests.dll" OutputXmlFile="test-results.xml" /> </Target>