让 TeamCity 运行 NUnit 测试,并集成 NCover 和 TypeMock?
基本上我想使用 TeamCity 的 NUnit 插件(程序,不一定是使用它的特定构建步骤)来运行我的单元测试,并使用 NCover 进行代码覆盖,并且由于我的单元测试使用 TypeMock 6,所以我也需要它在职的。
到目前为止,我已经尝试过:
只是基本上将 TeamCity NUnit 构建步骤指向我的 dll,但失败并显示以下错误消息:
<块引用>Typemock Isolator 需要与 Coverage Tool 链接才能运行,才能执行以下操作之一:
- 通过 Typemock Isolator 配置链接覆盖率工具
- 通过 TMockRunner.exe -link 运行测试
- 使用带有 Link 的 MSBuild 或 NAnt 的 TypeMockStart 任务
Trying为了找出正确的命令行,我尝试了以下方法:
<块引用>C:...\Isolator\6.0\TMockRunner.exe“C:\TeamCity...\JetBrains.BuildServer.NUnitLauncher.exe”v4.0 MSIL NUnit-2.5.9 MyAssembly.dll
这会失败并出现完全相同的错误。
设置在 TypeMock 的
mocking_on.bat
文件部分中找到的环境变量,这不会改变结果。
请注意,上面的示例尚未包含任何对 NCover 的引用,这是因为我已经在命令行上使用上面的示例进行了几个小时的修改,但仍然没有运行基本的单元测试。 NCover 是 TeamCity 的 nunit 启动器的额外选项,所以我希望这就像在我达到这个目标时启用它一样简单。
Basically I'd like to use the NUnit plugin for TeamCity (the program, not necessarily the specific build step using it) to run my unit tests, with NCover for code coverage, and since my unit tests uses TypeMock 6, I need that too working.
So far I've tried:
Just basically pointing the TeamCity NUnit build-step to my dll's, but that fails with the following error message:
Typemock Isolator needs to be linked with Coverage Tool to run, to enable do one of the following:
- link the Coverage tool through the Typemock Isolator Configuration
- run tests via TMockRunner.exe -link
- use TypeMockStart tasks for MSBuild or NAnt with Link
Trying to figure out the right command line, I tried this:
C:...\Isolator\6.0\TMockRunner.exe "C:\TeamCity...\JetBrains.BuildServer.NUnitLauncher.exe" v4.0 MSIL NUnit-2.5.9 MyAssembly.dll
This fails with the exact same error.
Setting the environment variables found in the
mocking_on.bat
file part of TypeMock, this doesn't change the outcome.
Note that the above examples doesn't contain any reference to NCover (yet), that's because I've been hacking around on the command line for a couple of hours with the above examples and still haven't gotten basic unit-tests running. NCover is extra options to the nunit-launcher of TeamCity so I hope this is as simple as just enabling that when I get that far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 TypeMock 要求您使用他们自己的运行程序 TMockRunner,因此无法仅使用 TeamCity 中的 GUI 选项来完成所有设置。
相反,我最终要做的是首先构建一个包含以下内容的自定义 msbuild 文件:
我将该文件保存到我的 TeamCity 服务器上的目录中。由于我不希望测试脚本成为我的存储库的一部分,因此我没有将其添加到源代码管理中(如果我得到的内容与我的代码不太相关,我可以在 Visual Studio 中构建并右键单击并运行测试)构建服务器我可能稍后会改变这个决定)。另外,我的 TeamCity 服务器只有 1 个构建代理,因此暂时对我有用。
除了上述文件之外,我还添加了以下批处理文件:
然后,我将以下两个构建步骤添加到我的 TeamCity 构建配置中:
我确保
coverage.zip
列在我的构建配置中的工件下,现在我得到了代码覆盖率、类型模拟和单元测试。到目前为止我唯一不知道如何实现的是,如果我单击使用普通 TeamCity GUI 来设置所有内容(减去 TypeMock)的构建配置的构建结果,我会得到列出的代码覆盖率简短摘要,这在上面的设置中不存在,但完整的报告以及 TeamCity 构建结果中的选项卡都有。
希望这可以为其他人节省一些麻烦。
Since TypeMock requires you to use their own runner program, TMockRunner, there's no way to just use the GUI options in TeamCity to get everything set up.
Instead, what I ended up doing was to first build a custom msbuild file with this contents:
This file I save to a directory on my TeamCity server. Since I didn't want the test script to be part of my repository, I didn't add it to source control (I can build and right-click and run tests from within Visual Studio, if I get something not so tied to my build server I might change that decision later). Also, I only have 1 build-agent for my TeamCity server so this works for me for the time being.
In addition to the above file, I added the following batch-file:
And then I added the following two build-steps to my TeamCity build configuration:
I made sure that
coverage.zip
was listed under artifacts in my build configuration, and now I got code coverage, typemock, and unit tests.Only thing I haven't figured out how to get so far is that if I click on the build result of a build configuration that uses the normal TeamCity GUI for setting up everything (minus TypeMock), I get a code coverage short summary listed, this is not present in the above setup, but the full report is, and the tab in the TeamCity build results.
Hopefully this can save someone else some trouble.
Lasse,
只要您使用 TeamCity GUI,使用 NCover 覆盖率运行应该只是选择使用它运行的简单问题。我从未尝试过将 Typemock 加入其中,所以我期待听到情况如何。
Lasse,
So long as you're using the TeamCity GUI, running with NCover coverage should just be a simple matter of selecting to run with it.I've never tried throwing Typemock into the mix, so I look forward to hearing how that goes.