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

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


当前回答

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

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

其他回答

I wouldn't go with MSTest. Although it's probably the most future proof of the frameworks with Microsoft behind it's not the most flexible solution. It won't run stand alone without some hacks. So running it on a build server other than TFS without installing Visual Studio is hard. The visual studio test-runner is actually slower than Testdriven.Net + any of the other frameworks. And because the releases of this framework are tied to releases of Visual Studio there are less updates and if you have to work with an older VS you're tied to an older MSTest.

我认为你使用的其他框架并不重要。从一个转换到另一个真的很容易。

我个人使用XUnit。Net或NUnit,这取决于我同事的偏好。NUnit是最标准的。XUnit。Net是最精简的框架。

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);
        }
    }
}

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

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

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

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