同时使用MSTest和NUnit? [英] Using both MSTest and NUnit?

查看:105
本文介绍了同时使用MSTest和NUnit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读有关MSTest和NUnit的信息时,我无法真正决定在项目中使用什么.我们使用TFS 2008和VS2010.

Reading about MSTest and NUnit I couldn't really decide what to use in my project. We use TFS 2008 and VS2010.

我喜欢MSTest,因为它已集成到VS2010,持续集成和代码覆盖率报告中. 我喜欢NUnit,因为它允许以一种很好的可读方式来表达复杂的断言语句.

I like MSTest because of its integration into VS2010, Continuous Integration and Code Coverage reports. I like NUnit because it allows to formulate complex assert statements in a nice, readable fashion.

跌倒

Stumbling upon http://alsagile.com/archive/2010/03/09/stop-the-war-between-nunit-and-mstest-make-them.aspx I ask the community: is it possible to use both?

我还考虑坚持使用MSTest并使用 Fluent断言为我提供一种更灵活的方式来声明断言.毕竟这不是最好的选择吗?

I also think about sticking to MSTest and use Fluent Assertions to give me a more flexible way in formulating assert statements. Wouldn't this be the best option after all?

推荐答案

我个人不喜欢混合两个框架的想法,就像

I personally don't like the idea of mixing two frameworks like it's mentioned in the article you are referring to.

使单元测试在两个测试框架下运行的可能条件是您不希望或不能在连续集成服务器上安装Visual Studio.

A possible condition to make your unit test run under both test frameworks could be that you do not want or can not install Visual Studio on your continuous integration server.

为澄清起见, MSTest 不是组装.

Just for clarification, MSTest is not the Visual Studio Unit Testing Framework defined in the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly.

要使您的单元测试能够在两个框架下运行,您需要定义一个构建常量(在此处为NUNIT),并借助命名空间别名,您最终会得到如下代码段:

To be able to let your unit test run under both frameworks you would need to define a build constant (here NUNIT) and with the help of preprocessor directives and namespace aliases you would end up with a snippet like this:

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestContext = System.Object;
using TestProperty = NUnit.Framework.PropertyAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
#endif

我相信我是通过 MSDN杂志文章.另一个有关此主题的有价值的博客文章将是:

I believe I came across this idea first through this MSDN Magazine article. Another worthwhile blog post covering this topic would be:

最后一个问题: Fluent Assertions 项目似乎是一个很好的库.如果您喜欢流畅的样式,我看不出有任何真正的原因为什么您不应该使用它.

To your last question: The Fluent Assertions project seems to be a good library. I do not see any real reasons why you shouldn't use it if you like the fluent style of it.

这篇关于同时使用MSTest和NUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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