They are pretty similar. The differences are minor.
- NUnit has test modules for parameterized tests; MSTest does not.
You can write
[TestCase(1, "one)] [TestCase(2, "two)] [TestCase(3, "three)] [TestCase(4, "four)] public void CanTranslate(int number, string expectedTranslation) { var translation = _sut.Translate(number); translation.Should().Be.EqualTo(expectedTranslation); }
instead of writing 4 tests or using a loop inside a test. Failed test error messages will be much clearer, and test results will always be conveniently grouped.
- NUnit tends to be more complete and flexible. For example, it comes with a cool set of attributes , such as Combinatorial.
for example
[Test, Combinatorial] public void MyTest([Values(1,2,3)] int x, [Values("A","B")] string s) { ... }
which is equivalent to running tests
MyTest(1, "A") MyTest(1, "B") MyTest(2, "A") MyTest(2, "B") MyTest(3, "A") MyTest(3, "B")
(see source page here )
MSTest always creates an instance of a test class for each test method that is executed. This is very useful since the Setup and TearDown methods will be run before each individual test, and all instance variables will be reset. With NUnit, you need to take care of instance variables that ultimately are shared between the tests (although this should not be a bis problem: a well-designed test must be isolated by design)
- With NUnit, abstract classes can be test devices, and you can inherit other test devices from it. MsTest does not have this feature.
MSTest is well integrated with Visual Studio. You will need a third-party plugin to work effectively with NUnit, such as ReSharper, Test Driven.NET or NCrunch
NUnit has a free version of Assert, so you can write
eg
Assert.That(result).Is.GreaterThan(9)
but not
Assert.Greater(9, result);
With SharpTestEx, you can even write:
result.Should().Be.GreaterThan(9);
and take advantage of the strong typed IntelliSense.
Arialdo martini
source share