在使用 NUnit 和 MSTest 进行单元测试之间切换
如何配置 .NET 解决方案(C#、.NET 2.0)以允许其他开发人员使用 NUnit 或 MSTest 对解决方案使用相同的单元测试?
背景:
在这个项目中,一些开发人员使用VS2005 Team Edition,其他开发人员使用VS2005 Pro,因此并非所有开发人员都能够运行MSTest。 鉴于这是一个企业项目,团队无法使用 TestDriven.net 或 ReSharper。 我知道将这些产品中的任何一个与 VS 一起使用都可以解决此问题,但考虑到授权购买许可证所需的时间,购买这些产品中的任何一个都不是一个可行的选择。
在此先感谢您的帮助, 魔术安迪。
How can I configure a .NET solution (C#, .NET 2.0) to to allow other developers to make use of the same unit tests for the solution using either NUnit or MSTest?
Background:
In this project, some developers use VS2005 Team Edition, and others make use of VS2005 Pro, so not all of the developers are able to run MSTest. Given that this is an Enterprise project, the team is not able to make use of TestDriven.net or ReSharper. I am aware using either of these products with VS would resolve this issue, but given the time it would take to authorize the purchase of licenses, buying either of these products isn't a viable option.
Thanks in advance for your help,
MagicAndi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现的最好的解决方案是使用我在
代码片段中的
NUNIT
指的是解决方案的自定义构建配置。 您可以使用 VS 配置管理器(通过 VS 工具栏或解决方案属性)创建它。 此外,您需要替换方法上 NUnit 的 Test 属性的所有实例,以使用 MSTest TestMethod 属性(反之亦然)。编辑:更新了上面的代码片段,以包含对评论中指出的问题 Jamie Ide 的可能修复。 请注意,我尚未成功测试此修复。 更新的代码片段取自 Simon 对此的评论 博客文章。
The best solution I have found is to make use of a simple piece of code I found in this article. Simply use this code snippet in the namespace section of each .cs test file:
The
NUNIT
in the code snippet refers to a custom build configuration for the solution. You can create this using the VS Configuration Manager (via the VS toolbar or the solution properties). Also, you need to replace all instances of the NUnit's Test attribute on your methods to make use of the MSTest TestMethod attribute (or vice versa).EDIT: Updated the code snippet above to include a possible fix for the issue Jamie Ide pointed out in the comments. Note, I haven't managed to test this fix. The updated code snippet is taken from a comment by Simon on this blog post.
如果您不想更改任何测试代码(即不想在顶部添加别名),这个垫片对我有用:
这对我通过 NUnit 运行 MSTest 很有用(至少在 Xamarin Studio 的单声道下)。 只需包含该文件并获取正确的引用即可(您可能需要不同的项目文件或条件引用) ,你很好。
If you don't want to change any test code (i.e. don't want to add the aliasing at the top), this shim works for me:
This has worked for me to run MSTest via NUnit (at least under mono with Xamarin Studio). Just include the file and get references right (you may need a different project file or conditional references), and you're good.
您是否混合了现有的测试? 如果没有,或者您不介意转换现有的 MSTest,我会在 NUnit 上进行标准化。 与 MSTest 相比,我更喜欢 NUnit; 它更快,并且不会强迫您在测试类中添加 TestContext 废话。 它还与 CI 服务器更兼容。
Do you have a mix of existing tests? If not, or you don't mind converting existing MSTests, I would standardize on NUnit. I strongly prefer NUnit over MSTest; it's faster and it doesn't force you to have the TestContext nonsense in your test classes. It's also more compatible with CI servers.