.Net 4.0下的单元测试和Test Runner问题

发布于 2024-09-06 18:37:36 字数 704 浏览 2 评论 0原文

我们正在尝试将 .Net 3.5 解决方案迁移到 .Net 4.0,但在使用使用 .Net Framework 4.0 版本构建的程序集进行操作的测试框架方面遇到了一些麻烦。

之前,我们在 NAnt 脚本中使用了 NUnit 2.4.3.0 和 NCover 1.5.8.0,但 NUnit 2.4.3.0 不喜欢 .Net 4.0 项目。因此,我们在测试项目本身中升级到了较新版本的 NUnit 框架,但随后发现 NCover 1.5.8.0 不支持该版本的 NUnit。

我们在代码中收到错误,表明程序集是使用比当前使用的 .Net Framework 版本更新的版本构建的,因为它使用 .Net Framework 2.0 来运行工具。

然后我们尝试使用 Gallio 的 Icarus 测试运行器 GUI,但发现它和 MbUnit 仅支持 .Net Frameword 3.5 版本,结果是“测试将被忽略”。

就覆盖范围而言(用于向 CruiseControl.net 报告),我们发现 PartCover 是替代 NCover 的良好候选者(因为新版本的 NCover 相当昂贵,而且 PartCover 是免费的),但是这还只是几步,因为我们无法让测试运行者首先工作!

任何人都可以阐明将以与我上面描述的方式相同的方式在 .Net 4.0 下运行的测试框架吗?如果没有,我担心我们可能不得不恢复使用 .Net 3.5,直到我们当前使用的工具制造商有机会升级到 .Net 4.0。

谢谢。

We're trying to migrate a .Net 3.5 solution into .Net 4.0, but are experiencing complications with the testing frameworks that can operate using an assembly that is built using version 4.0 of the .Net Framework.

Previously, we used NUnit 2.4.3.0 and NCover 1.5.8.0 within our NAnt scripts, but NUnit 2.4.3.0 doesn't like .Net 4.0 projects. So, we upgraded to a newer version of the NUnit framework within the test project itself, but then found that NCover 1.5.8.0 doesn't support this version of NUnit.

We get errors in the code saying words to the effect of the assembly was built using a newer version of the .Net Framework than is currently in use, as it's using .Net Framework 2.0 to run the tools.

We then tried using Gallio's Icarus test runner GUI, but found that this and MbUnit only support up to version 3.5 of the .Net Frameword and the result is "the tests will be ignored".

In terms of the coverage side of things (for reporting into CruiseControl.net), we have found that PartCover is a good candidate for substituting-out NCover, (as the newer version of NCover is quite dear, and PartCover is free), but this is a few steps down the line yet, as we can't get the test runners to work first!!

Can any shed any light on a testing framework that will run under .Net 4.0 in the same way as I've described above? If not, I fear we may have to revert back to using .Net 3.5 until the manufacturers of the tooling that we're currently using have a chance to upgrade to .Net 4.0.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老娘不死你永远是小三 2024-09-13 18:37:36

是的 - 我自己已经解决了这个问题。以下是方法,以防其他人遇到同样的问题。

NUnit 2.5.5 现已推出,它支持使用 .Net Framework v4.0 构建项目,但是你必须使用一个附加参数,即/framework=4.0.30319,在NAnt中通过NCover使用时它看起来像这样:

<exec program="C:\Program Files\TestDriven.NET 2.0\NCover\1.5.8\NCover.Console.exe">
 <arg value=""C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit-console.exe""/>
 <arg value=""bin/release/myProject.Test.dll" /framework=4.0.30319"/>
 <arg value="/xml"/>
 <arg value="bin/release/myProject.Test-dll-results.xml"/>
 <arg value="//x"/>
 <arg value="bin/release/myProject.Test-dll-coverage-results.xml"/>
 <arg value="//q"/>
 <arg value="//a"/>
 <arg value="myProject.Test"/>
</exec> 

仅将NUnit升级到2.5。 5(以及添加此标志)现在只需对构建脚本进行很少的更改即可工作,这很好。

因此,总而言之:

我的 NAnt 脚本调用 NCover 1.5.8,并调用 NUnit 2.5.5,后者测试使用 .Net 4.0 构建的单元测试程序集 .dll。 NUnit 生成第一个输出文件 (bin/release/myProject.Test-dll-results.xml),然后由 NCover 拾取并处理为第二个输出结果文件 (bin/release/myProject.Test-dll-coverage) -results.xml),然后可以简单地将其包含到 Cruise Control 的 ccnet.config 文件中,以便在每次构建后自动包含在 webdashboard 中。

简单的。希望它对其他人有帮助!

Right - have sort of fixed this myself. Here's how, in case anyone else has the same problem.

NUnit 2.5.5 is now out and this supports projects build using .Net Framework v4.0, but you have to use an additional parameter, namely /framework=4.0.30319, which looks something like this when used in NAnt, through NCover:

<exec program="C:\Program Files\TestDriven.NET 2.0\NCover\1.5.8\NCover.Console.exe">
 <arg value=""C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit-console.exe""/>
 <arg value=""bin/release/myProject.Test.dll" /framework=4.0.30319"/>
 <arg value="/xml"/>
 <arg value="bin/release/myProject.Test-dll-results.xml"/>
 <arg value="//x"/>
 <arg value="bin/release/myProject.Test-dll-coverage-results.xml"/>
 <arg value="//q"/>
 <arg value="//a"/>
 <arg value="myProject.Test"/>
</exec> 

With only upgrading NUnit to 2.5.5 (as well with adding this flag) this now works with very little change to the build scripts, which is good.

So, in summary:

My NAnt script calls out to NCover 1.5.8 and that calls NUnit 2.5.5 which tests my unit test assembly .dll that was built using .Net 4.0. NUnit generates the first output file (bin/release/myProject.Test-dll-results.xml), which is then picked up by NCover and is processed into the second output results file (bin/release/myProject.Test-dll-coverage-results.xml), which can then be simply included into Cruise Control's ccnet.config file for it's automatic inclusion within the webdashboard after each build.

Simple. Hope it helps someone else!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文