MSBuild to run unit tests

早过忘川 提交于 2020-01-15 05:55:07

问题


I am trying to configure CruiseControl .net to build our repository code periodically and run the tests included in the solution. I have configured the retrieving code from the svn server and building part. But I am unable to run tests on it. MSBuild keeps on complaining that.

error MSB4057: The target "Test" does not exist in the project.

I also tried running the tests through command line to see if that works with the same error. I used: MSBuild.exe TestProject.csproj /t:Test

My configuration is something like this:

<tasks>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\MainProject</workingDirectory>                
        <projectFile>MainProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Build</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\TestProject</workingDirectory>                
        <projectFile>TestProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Test</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>  
    </tasks>

I would appreciate any hint in the right direction.


回答1:


You havent explained what test framework you're using, which is pretty key here.

For MSTest, this invocation stuff is part of TFS [as the runner stuff is part of Visual Studio, which is why a Task to run MSTest can not be part of MSBuild, which is part of the .NET Framework -- this is also why MSTest forces [in 2010, a subset of] Visual Studio to be installed on your build server (there are a good few questions around here on that topic)]

For xUnit.net, people do stuff like this

For NUnit there's a task that you can supply a list of files to.

Bottom line - one adds a Test custom target to a .csproj file which triggers the salient MSBuild wrapper task for invoking your test runner.



来源:https://stackoverflow.com/questions/3463570/msbuild-to-run-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!