After Visual Studio 2015 was used, it was found unable to run XUnit unit test, xunit.net Runner does not support Vs2015,testdriven.net and does not support VS2015.
Wait for them to support VS2015, do not know to wait until monkey still wait until Ma Yue. So today I decided to wait and try to run the unit test with MSBuild to solve the problem.
NuGet on a search, found that someone has provided the xunit. MSBuild, you can use it directly.
Install the NuGet package in the Unit test project:
Install-package Xunit. Msbuild
Find the following configuration in the corresponding. csproj file:
<Project= ". \packages\xunit. Msbuild.1.9.2.3\build\xunit. Msbuild.targets " Condition=" Exists ('.. \packages\xunit. Msbuild.1.9.2.3\build\xunit. Msbuild.targets ') "/>
Xunit. The contents of the Msbuild.targets file are as follows:
<?XML version= "1.0" encoding= "Utf-8"?><ProjectToolsVersion= "4.0"xmlns= "http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTaskassemblyfile= "$ (msbuildthisfiledirectory): \tools\xunit.runner.msbuild.dll "TaskName= "Xunit.Runner.MSBuild.xunit" /> <PropertyGroupCondition= "' $ (runxunittests) ' = = '"> <runxunittestsCondition= "' $ (Configuration) ' = = ' Release '">True</runxunittests> </PropertyGroup> <PropertyGroup> <BuildDependsOn>$ (BuildDependsOn); Executexunittests</BuildDependsOn> <Rebuilddependson>$ (Rebuilddependson); Executexunittests</Rebuilddependson> </PropertyGroup> <TargetName= "Executexunittests"Condition= "' $ (runxunittests) ' = = ' true '" > <XunitAssembly= "$ (OutputPath) $ (AssemblyName). dll" /> </Target></Project>
As you can see from this msbuild configuration, executexunittests is the MSBuild command that runs the unit test, and the trigger condition is when the project is compiled in release mode.
Then, just modify the configuration in the. csproj, and call this executexunittests command after the project is compiled:
<Name= "Afterbuild"></Target >
When configured, the results of the unit tests are displayed in the Output window of Visual Studio at compile time:
Panax Notoginseng> postmodeltest.postmodel_required_validation100 0.410 seconds Panax Notoginseng>notoginseng>build succeeded.
If the unit test fails, it is displayed as follows:
1> 1100.428 seconds1>1> Build FAILED. 1>1: xx:03.9101 0 skipped ==========
The status bar of Visual Studio also displays build failed.
This display is not intuitive, but it is convenient to run unit tests at compile time, and unit test failures can cause compilation to fail, highlighting the importance of unit testing.
Run Xunit unit test with MSBuild