将 NUnit 与 Visual C# Express 2010 和 .net 4 结合使用
我已经浏览了 SO 和网络很长一段时间了,我正在努力寻找有关如何设置我的 C# 项目进行单元测试的任何信息。
我从 NUnit 主站点 http://www.nunit.org 开始,下载包含一个可以运行的 GUI你的单元测试,听起来很不错。仅当我尝试将 GUI 指向我的 .exe 时,我会立即收到一条错误消息,指出 NUnit 并非设计为与此框架一起运行。这让我想到也许 NUnit 不适用于 .net 4。显然确实如此,网上很多人似乎都说他们正在使用 .net 4 运行 NUnit 单元测试....当然他们似乎并不这样做继续说怎么做。
在 google 上点击了一下,我发现 NUnit 开发的核心成员之一是一个名叫 Charlie Poole 的家伙。我发现他在这里有一个启动板:https://launchpad.net/nunit-xtp。版本号比 NUnit 主站点上的版本号新。然而,当我下载该项目时,它只是 NUnit 框架的代码库和解决方案,没有 GUI。包含一个命令行运行程序,但我真的需要一些视觉效果。
我们确实有 jetbrains teamcity 作为 BMS,所以我现在正在尝试以某种方式将 NUnit 集成到构建管道中。如果有人能够阐明如何让 NUnit 使用 c# 的 Express 版本,那将非常有帮助。
编辑:我现在有 teamcity BMS 运行测试,所以这部分不再是问题。然而,每次等待构建只是为了发现 NullException 错误或其他错误并不能真正解决问题。我必须让 GUI 运行程序正常工作。我发现这个问题NUnit isn't running Visual Studio 2010 code但是即使这样也不能解决我的问题。该错误现已更新为版本 v4.0.30319,因此配置更改已生效。还是老错误:(
I have looked around SO and the web for quite some time now and I am struggling to find any information for how to setup my C# project for unit tests.
I started on the NUnit main site http://www.nunit.org, the download includes a GUI to run your unit tests, sounds mint. Only when I try and point the GUI to my .exe, I get an error immediately saying that NUnit is not designed to be run with this framework. That got me thinking that maybe NUnit doesn't work with .net 4. Apparently it does, plenty of people online seem to state that they are running NUnit unit tests with .net 4 .... of course they don't seem to go on to say how.
Clicking around google I found what appears to be one of the core members of the NUnit development is a dude called Charlie Poole. I found he had a launchpad here: https://launchpad.net/nunit-xtp. The version numbers are newer than on the main NUnit site. When I downloaded the project however, it is just the codebase and solution for the NUnit framework with no GUI. There is a command line runner included but I really need something visual.
We do have jetbrains teamcity as a BMS so I am now going down the path of maybe trying to integrate NUnit into the build pipeline somehow. If anyone can shed any light on how they got NUnit working with an express edition of c# that would be wonderfully helpful.
Edit : I have the teamcity BMS running the tests now, so that part is no longer a problem. However, waiting for the build each time just to find a NullException error or something doesn't really cut it. I have to get the GUI runner working. I found this question NUnit isn't running Visual Studio 2010 code but even that isn't fixing it for me. The error has now updated to read version v4.0.30319, so the config changes have taken effect. Same old error though :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我猜出来了。这里有一个非常相似的问题:
NUnit 不运行 Visual Studio 2010 代码
仅运行它不运行的内容'值得一提的是,NUnit 有多个配置文件。我只是假设编辑 nunit.exe.config 就足够了。正如我在错误消息中看到的那样,这确实更新了设置。但是,nunit gui 运行程序必须使用其他多个 .config 文件之一。我只是简单地浏览了所有这些并添加了两个必需的设置。
确保运行正确的 .exe。一种称为“nunit.exe”,它似乎是正确的使用方式。另一种称为“nunit-x86.exe”,如果您的应用程序是 32 位,那么您必须运行这个。如果“nunit.exe”被命名为“nunit64.exe”,我想我会更早注意到这一点。
您还必须确保检查 CLR 的版本号与粘贴到这些配置文件中的设置相匹配。使用此链接可以计算出您当前的 CLR 版本号。 如何找出我正在使用的 CLR?< /a> 我是 Microsoft Visual C# 2010 Express,我的 CLR 版本号是 v4.0.30319
Right I sussed it out. there is a very similar question here:
NUnit isn't running Visual Studio 2010 code
Only what it doesn't mention is that there are multiple config files for NUnit. I just assumed it would suffice to edit nunit.exe.config. This did indeed update the settings as I saw it in the error message. However, the nunit gui runner must make use of one of the other multiple .config files. I simply went through them all and added the two required settings.
Make sure that you run the correct .exe. One is called "nunit.exe" and it seems like the correct one to use. The other one is called "nunit-x86.exe" and if your app is 32bit then you have to run this one. If "nunit.exe" was names "nunit64.exe" I think I would have noticed that much sooner.
You must also make sure that you check the version number of the CLR matches the setting you are pasting into those config files. Use this link to work out your current CLR version number. How do I find out what CLR i am using? I am Microsoft Visual C# 2010 Express and my CLR version number is v4.0.30319
单元测试应该位于单独的程序集中(类型为类库)。如果您将 NUnit 指向该程序集,它将运行。这同样适用于命令行运行程序(通常在自动构建过程中使用)。
The unit tests should be in a seperate assembly (of type class library). If you point NUnit to that assembly, it will run. Same applies to the command line runner (which is normaly used in automated build processes).
默认的 NUnit 发行版包含一个名为“nunit.exe”的 GUI 运行程序。如果使用它,我会在测试程序集上设置调试目标,以使用适当的配置加载 GUI 运行器。
The default NUnit distro includes a GUI runner called 'nunit.exe'. If using it, I set my debug target on my test assembly to load the GUI runner with the appropriate config.