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

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


当前回答

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是最精简的框架。

其他回答

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是最精简的框架。

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

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

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

考虑用另一个测试框架补充而不是取代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。