[英]Unit test, NUnit or Visual studio?
I'm using Visual studio (sometimes resharper) to run my unit test. 我正在使用Visual studio(有时是resharper)来运行我的单元测试。
I heard about NUnit, but I don't know many things about it... 我听说过NUnit,但我不知道很多事情......
Should I care about it ? 我应该关心它吗? Can it offer something better than visual studio?
它能提供比视觉工作室更好的东西吗?
Should I Use NUnit and why? 我应该使用NUnit吗?为什么?
NUnit has few advantages over MS-Test NUnit与MS-Test相比几乎没有什么优势
Assert.AreEqual(expected, actual)
vs Assert.That(actual, Is.EqualTo(expected))
Assert.AreEqual(expected, actual)
vs Assert.That(actual, Is.EqualTo(expected))
[TestCase]
! [TestCase]
! NUnit allows for parameter-ized tests. From my current perspective (after 8 months of development with about 10 developers on average) I would advise against using MSTest for the following reasons 从我目前的角度来看(经过8个月的开发,平均约有10个开发人员)我建议不要使用MSTest,原因如下
In other words, if I would have to decide again 8 months ago, I would probably take NUnit. 换句话说,如果我必须在8个月前再次决定,我可能会采取NUnit。 I may not have the integrated test results report, but developers would have a more seamless testing experience.
我可能没有集成的测试结果报告,但开发人员可以获得更加无缝的测试体验。
Here is my experience with MS Test 这是我对MS Test的体验
Addition: We have some more tests now, can't even say how many. 另外:我们现在有更多的测试,甚至不能说多少。 It is impossible to run them all anymore from Visual Studio, because of OutOfMemoryExceptions and other instability problems.
由于OutOfMemoryExceptions和其他不稳定性问题,不可能再从Visual Studio中运行它们。 We run the tests from scripts.
我们从脚本运行测试。 It would be easy to view test results in Visual Studio, but when the solution is open, VS crashes (every time).
在Visual Studio中查看测试结果会很容易,但是当解决方案打开时,VS会崩溃(每次)。 So we need to search the failing tests using text search.
所以我们需要使用文本搜索来搜索失败的测试。 There is no advantage of an integrated tool anymore.
再也没有集成工具的优势。
Another Update : We are using VS 2013 now. 另一个更新 :我们现在正在使用VS 2013。 A lot of things changed.
很多事情发生了变化。 They rewrote the MS Test test runner for the third time since we started.
自从我们开始以来,他们第三次重写了MS Test测试运行器。 This caused a lot of breaking changes, but neither new version was doing anything better.
这引起了很多重大变化,但新版本都没有做得更好。 We are glad that we didn't use the fancy features of MS Test, because they are all not supported anymore.
我们很高兴我们没有使用MS Test的精彩功能,因为它们都不再受支持了。 It's really a shame.
这真是一个耻辱。 We are still using scripts to build and run all unit tests, because it is handier.
我们仍在使用脚本来构建和运行所有单元测试,因为它更方便。 Visual Studio required a few minutes to start running tests (time measures after compilation until first test starts).
Visual Studio需要几分钟才能开始运行测试(编译后的时间测量,直到第一次测试开始)。 They probably fixes it with an update and this might be a specific problem of our project.
他们可能会通过更新修复它,这可能是我们项目的一个特定问题。 However, Resharper is much quicker when running the same tests.
但是,Resharper在运行相同测试时要快得多。
Conclusion : At least in combination with Resharper, MS Test is useful. 结论 :至少与Resharper结合使用,MS Test非常有用。 And I hope that they finally find out how the test runner should be written and won't do this kind of breaking changes when we update Visual Studio next time.
我希望他们最终能够找到如何编写测试运行器,并且在下次更新Visual Studio时不会进行这种重大更改。
NUnit can be used in combination with visual studio. NUnit可与visual studio 结合使用。 It is a framework not a separate program.
它是一个框架而不是一个单独的程序。 So you could care an see if it suits you :).
所以你可以关心看看它是否适合你:)。
alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=nunitit&DownloadId=61802 alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=nunitit&DownloadId=61802
"After installing the plugin you'll find a new submenu under the tools menu." “安装插件后,你会在工具菜单下找到一个新的子菜单。”
See http://nunitit.codeplex.com/ for more information on importing it. 有关导入它的更多信息,请参见http://nunitit.codeplex.com/ 。
Also, a lot can be found using the search of SO. 此外,使用搜索SO可以找到很多。 This topic lists advantages of NUnit over MS standard testing for instance.
本主题列出了NUnit优于MS标准测试的优势。
Biggest advantage MS-Test over NUnit is MS-Test can generate mock objects using Reflection. NUnit的最大优势MS-Test是MS-Test可以使用Reflection生成模拟对象。 I found it very usefull
我发现它非常有用
NUnit适用于VS的标准版。
NUnit is a unit testing framework, which is also supported by resharper. NUnit是一个单元测试框架,resharper也支持它。 I think you are using Microsoft's unit testing framework, so NUnit is just an alternative to Microsoft's product ;)
我认为您使用的是Microsoft的单元测试框架,因此NUnit只是Microsoft产品的替代品;)
Here is the link to the homepage of NUnit: http://nunit.org 这是NUnit主页的链接: http : //nunit.org
我不确定其他人,但NUnit提供了很好的GUI和控制台来运行你的单元测试,你也可以生成NUnit测试执行结果的报告,这将给出测试失败或通过的详细信息以及它的时间参加你的单元测试
In NUnit , tests are not executed in parallel. 在NUnit中 ,测试不是并行执行的。 Rather, it appears that all tests execute on a single thread.
相反,似乎所有测试都在单个线程上执行。 In MSTest, each test is instantiated on a separate thread, this results the runs being interleaved.
在MSTest中,每个测试都在一个单独的线程上实例化,这会导致运行交错。 Therefore, if test A depends on test B for its success, it likely will fail as test B will likely start running as test A is running.
因此,如果测试A依赖于测试B的成功,它可能会失败,因为测试B可能会在测试A运行时开始运行。
If you are using Visual Studio You have to Use NUnit for doing unit test, and if you are running java(Netbeans) you have to use JUnit for unit test. 如果您使用的是Visual Studio,则必须使用NUnit进行单元测试,如果您正在运行java(Netbeans),则必须使用JUnit进行单元测试。
Here is an example for a simple calculator unit test 这是一个简单的计算器单元测试的例子
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SimpleCalculator;
using NUnit.Framework;
namespace CalculatorTest
{
[TestFixture]
public class Class1
{
public Calculator _calculator;
[TestFixtureSetUp]
public void Initialize()
{
_calculator = new Calculator();
}
[Test]
public void DivideTest()
{
int a = 10;
int b = 2;
int expectedValue = a / b;
int actualvalue = _calculator.Divide(a, b);
Assert.AreEqual(expectedValue, actualvalue,"Failure");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.