有很多用于。net的单元测试框架。我找到了这个功能比较:http://xunit.github.io/docs/comparisons.html

现在我要为我们选择一个最好的。但如何?这重要吗?哪一种是最有前途的,背后有良好势头的?我应该关心功能吗?虽然xUnit似乎是最现代的,专门为。net设计的,但NUnit似乎又是被广泛接受的。MSTest已经集成到Visual Studio中了…


当前回答

It's not a big deal on a small/personal scale, but it can become a bigger deal quickly on a larger scale. My employer is a large Microsoft shop, but won't/can't buy into Team System/TFS for a number of reasons. We currently use Subversion + Orcas + MBUnit + TestDriven.NET and it works well, but getting TD.NET was a huge hassle. The version sensitivity of MBUnit + TestDriven.NET is also a big hassle, and having one additional commercial thing (TD.NET) for legal to review and procurement to handle and manage, isn't trivial. My company, like a lot of companies, are fat and happy with a MSDN Subscription model, and it's just not used to handling one off procurements for hundreds of developers. In other words, the fully integrated MS offer, while definitely not always best-of-bread, is a significant value-add in my opinion.

我认为我们将保持当前的步骤,因为它是有效的,我们已经在组织上克服了困难,但我确实希望MS在这个领域有一个引人注目的产品,这样我们就可以巩固和简化我们的开发堆栈。

其他回答

It's not a big deal on a small/personal scale, but it can become a bigger deal quickly on a larger scale. My employer is a large Microsoft shop, but won't/can't buy into Team System/TFS for a number of reasons. We currently use Subversion + Orcas + MBUnit + TestDriven.NET and it works well, but getting TD.NET was a huge hassle. The version sensitivity of MBUnit + TestDriven.NET is also a big hassle, and having one additional commercial thing (TD.NET) for legal to review and procurement to handle and manage, isn't trivial. My company, like a lot of companies, are fat and happy with a MSDN Subscription model, and it's just not used to handling one off procurements for hundreds of developers. In other words, the fully integrated MS offer, while definitely not always best-of-bread, is a significant value-add in my opinion.

我认为我们将保持当前的步骤,因为它是有效的,我们已经在组织上克服了困难,但我确实希望MS在这个领域有一个引人注目的产品,这样我们就可以巩固和简化我们的开发堆栈。

考虑用另一个测试框架补充而不是取代MSTest。您可以保持Visual Studio MSTest集成,同时获得功能更全的测试框架的好处。

例如,我使用xUnit与MSTest。添加对xUnit.dll程序集的引用,然后执行如下操作。令人惊讶的是,它就是工作!

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Assert = Xunit.Assert;  // <-- Aliasing the Xunit namespace is key

namespace TestSample
{
    [TestClass]
    public class XunitTestIntegrationSample
    {
        [TestMethod]
        public void TrueTest()
        {
            Assert.True(true);  // <-- this is the Xunit.Assert class
        }

        [TestMethod]
        public void FalseTest()
        {
            Assert.False(true);
        }
    }
}

这没什么大不了的,在它们之间切换很容易。集成MSTest也不是什么大问题,只需获取testdriven.net。

就像前一个人说的选择一个嘲弄的框架,我目前最喜欢的是Moq。

Nunit不能很好地与c++中的混合模式项目一起工作,所以我不得不放弃它

NUnit可能是最受第三方工具支持的。它也比其他三个存在的时间长。

我个人不太关心单元测试框架,以我之见,模拟库更重要(并且更能锁定你)。选一个,然后坚持下去。