MSBuild运行单元测试 [英] MSBuild to run unit tests

查看:279
本文介绍了MSBuild运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图配置CruiseControl .net定期构建我们的代码库代码,并运行解决方案中包含的测试。我已经配置从svn服务器和构建部分的检索代码。但我无法对其运行测试。 MSBuild不断抱怨。


错误MSB4057:目标测试不会在项目中存在


我也试过通过命令行运行测试,看看是否有同样的错误。我使用:MSBuild.exe TestProject.csproj / t:Test



我的配置是这样:

 < tasks> 
< msbuild>
<可执行文件> C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe< / executable>
< workingDirectory> C:\ WorkingingDir\build\MainProject< / workingDirectory>
< projectFile> MainProject.csproj< / projectFile>
< buildArgs> / noconsolelogger / p:Configuration = Debug / v:diag< / buildArgs>
< targets> Build< / target>
< timeout> 900< / timeout>
< logger> C:\Program文件(x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll< / logger>
< / msbuild>
< msbuild>
<可执行文件> C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe< / executable>
< workingDirectory> C:\ WorkingingDir\build\TestProject< / workingDirectory>
< projectFile> TestProject.csproj< / projectFile>
< buildArgs> / noconsolelogger / p:Configuration = Debug / v:diag< / buildArgs>
< targets>测试< / targets>
< timeout> 900< / timeout>
< logger> C:\Program文件(x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll< / logger>
< / msbuild>
< / tasks>

我会感谢任何正确方向的提示。



对于MSTest,这是一个非常重要的测试框架,调用的东西是 TFS的一部分 [因为runner的东西是Visual Studio的一部分,这就是为什么运行MSTest的任务不能成为MSBuild的一部分,这是.NET Framework的一部分 - 这也是为什么MSTest强制要在您的构建服务器上安装Visual Studio(在2010年,子集)是这个话题的好几个问题)]



对于xUnit.net,人们会这样做



对于NUnit,有一个任务,你可以提供一个文件列表。



底线 - 一个测试自定义目标添加到.csproj文件触发显着的MSBuild用于调用测试运行器的包装程序任务。


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.

解决方案

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.

这篇关于MSBuild运行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆