The document discusses various unit testing frameworks for .NET such as MSTest v2, NUnit, and xUnit.net. It provides information on the key features of each framework, how to install and set them up, how to write tests, and comparisons between the frameworks. The document recommends NUnit as it has the richest set of assertions, supports data-driven testing well, and has full documentation available, which would be important for a new development team to learn to use the framework effectively.
3. …with Mocks
Mock Library
In Isolation
Unit Testing
Replace
Dependencies…
Dependency
Injection
Framework
Automatic
Unit Testing
Framework
mbUnit
nUnit
xUnit.Net
Mstest v2
By hand
Spring.Net
Castle/Windsor
Unity
StructureMap
nMock
EasyMock
Rhino.Mocks
TypeMock
Continuous
Integration
CrouiseControl.Net
VS Team System
GitLab CI
Microsoft Azure
etc.
4. Microsoft Test Framework "MSTest V2” - Open Source Unit Testing framework evolved from the MSTest
framework - URL: https://github.com/Microsoft/testfx
xUnit.net - Open Source Unit Testing framework written by original inventor of Nunit v2.
URL: https://xunit.github.io/
Nunit – Open Source Unit Testing for .NET initialy ported from JUnit. URL: http://www.unit.org/
Unit Testing Frameworks for .NET
5. MSTest v2
• MSTest v2 is fully integrated with Visual
Studios and works natively without the need
for any plugins.
• MSTest v2 is better suited for only using
Microsoft technologies rather than mixed
technology environments.
6. • Excellent availability of learning resources
Due to it's popularity and active development, plenty of
learning resources (such as detailed documentation and
various tutorials) exist for learning NUnit.
• Widely used
NUnit is one of the most popular testing frameworks
for .NET. Other than giving a certain sense of security in
the continuation of the project, it also means that there
are a lot of third-party resources, guides and tutorials
available for NUnit.
• The constraint-based Assert model[1].
Nunit 3.0
7. xUnit.net
• Single object instance per test method: It allows complete isolation of test methods that
allow developers to independently run tests in any order.
• No Setup & Teardown attributes: These methods are decorated with attributes named
SetUp and TearDown respectively. The down side is that it unnecessarily creates confusion
and make developers to hunt around the presence and absence of such methods. It is
more productive to write code set up and tear down code within test methods itself.
Hence, in xUnit.Net pink slip is given to these unproductive attributes.
• Reduced set of attributes: For example, unlike nUnit it doesn't require [TextFixture] &
[TestMethod] attributes to declare a test while it requires only [Fact] attribute decorated
on test method.
• xUnit’s terminology adheres TDD closely (Fact, Theory)
• Automation: xUnit has great ability for test automation and can smoothly work in
conjunction with other testing framework. It is highly extensible and open for
customization.
• Lack of documentation
• Supported and used by Microsoft itself(?)
8. Installation
MSTest v2 NUnit x.Unit.net
Full MSTest v2install via
NuGet. Full NUnit install via NuGet.
Full x.Unit.net install via
NuGet.
n/a NUnitLite install via NuGet. n/a
n/a Zip and/or MSI file download. n/a
n/a Combined Approach n/a
9. Data driven testing
MSTest v2 NUnit xUnit.net
Inline data
DataRow,
DynamicData TestCase Attribute [Theory]
Separate DataSource TestCaseSource Attribute Xunit.Sdk.DataAttribute
Objectivity.Test.Automation
+ + +
11. NUnit 3.x MSTest 15.x xUnit.net 2.x Comments
[Test] [TestMethod] [Fact] Marks a test method.
[TestFixture] [TestClass] n/a
xUnit.net does not require an attribute for a test class; it looks for
all test methods in all public (exported) classes in the assembly.
Assert.That
[ExpectedException]
Assert.Throws
xUnit.net has done away with the ExpectedException attribute in
favor of Assert.Throws.Record.Exception Record.Exception
[SetUp] [TestInitialize] Constructor
We believe that use of [SetUp] is generally bad. However, you
can implement a parameterless constructor as a direct
replacement. See
[TearDown] [TestCleanup] IDisposable.Dispose
We believe that use of [TearDown] is generally bad. However,
you can implement IDisposable.Dispose as a direct replacement.
[OneTimeSetUp] [ClassInitialize] IClassFixture<T>
To get per-class fixture setup, implement IClassFixture<T> on
your test class.
[OneTimeTearDown] [ClassCleanup] IClassFixture<T>
To get per-class fixture teardown, implement IClassFixture<T> on
your test class.
n/a n/a ICollectionFixture<T>
To get per-collection fixture setup and teardown,
implement ICollectionFixture<T> on your test collection.
[Ignore("reason")] [Ignore] [Fact(Skip="reason")]
Set the Skip parameter on the [Fact] attribute to temporarily skip a
test.
[Property] [TestProperty] [Trait] Set arbitrary metadata on a test
Attributes
12. NUnit 3.x (Constraint) MSTest 15.x xUnit.net 2.x Comments
Is.EqualTo AreEqual Equal MSTest and xUnit.net support generic versions of this method
Is.Not.EqualTo AreNotEqual NotEqual MSTest and xUnit.net support generic versions of this method
Is.Not.SameAs AreNotSame NotSame
Is.SameAs AreSame Same
Does.Contain Contains Contains
Does.Not.Contain DoesNotContain DoesNotContain
Throws.Nothing n/a DoesNotThrow Ensures that the code does not throw any exceptions
n/a Fail n/a xUnit.net alternative: Assert.True(false, "message")
Is.GreaterThan n/a n/a xUnit.net alternative: Assert.True(x > y)
Is.InRange n/a InRange Ensures that a value is in a given inclusive range
Is.AssignableFrom n/a IsAssignableFrom
Is.Empty n/a Empty
Is.False IsFalse False
Is.InstanceOf<T> IsInstanceOfType IsType<T>
Is.NaN n/a n/a xUnit.net alternative: Assert.True(double.IsNaN(x))
Is.Not.AssignableFrom<T> n/a n/a xUnit.net alternative: Assert.False(obj is Type)
Is.Not.Empty n/a NotEmpty
Is.Not.InstanceOf<T> IsNotInstanceOfType IsNotType<T>
Is.Not.Null IsNotNull NotNull
Is.Null IsNull Null
Is.True IsTrue True
Is.LessThan n/a n/a xUnit.net alternative: Assert.True(x < y)
Is.Not.InRange n/a NotInRange Ensures that a value is not in a given inclusive range
Throws.TypeOf<T> n/a Throws<T> Ensures that the code throws an exact exception
Asserts
13. ExtendingMSTest v2 NUnit x.Unit.net
Framework Extensibility for Trait Attributes Custom Attributes n/a
+ Load-Time Interfaces n/a
+ IFixtureBuilder n/a
+ ITestBuilder n/a
+ ISimpleTestBuilder n/a
+ IParameterDataSource n/a
+ IImplyFixture n/a
+ IApplyToTest n/a
Extensibility for Custom Test Execution
Execution-Time Interfaces Test method extensibility
+ IApplyToContext n/a
+ ICommandWrapper n/a
n/a Custom Constraints n/a
Framework Extensibility for Custom AssertionsCustom Asserts Assert extensibility.
n/a Engine Extensibility Project Loaders n/a
n/a Result Writers n/a
n/a Framework Drivers n/a
n/a Event Listeners n/a
Framework Extensibility for Custom Test Data Source
n/a n/a
14. Logging and reporting
MSTest v2 NUnit xUnit.net
Output + Text Output from Tests Spec +
Logging
log4net log4net log4net
Nlog Nlog Nlog
ReportUnit reportunit reportunit n/a
Allure Test Report + + +
Test Results in XML n/a
+
+
Performance
n/a n/a xunit.performance
Nbench Nbench Nbench
Record n/a NUnit Video Recorder
n/a
15. Performance of frameworks
These were timed using benchmark solutions of 10,000 tests. Visual Studio 2017 15.5 Preview 2 + NUnit
Adapter v3.9.0, published on 11 Oct 2017 + xUnit v2.3.1 published on 27 Oct 2017. [15]
Test Framework Test Discovery (secs) Test Execution (secs)
xUnit.net 6.4 68
NUnit 5.5 16.7
MSTest v2 5.2 11.74
19. Conclusion
All frameworks have their pros and cons, their detractors and
supporters.
MSTest v2, Nunit 3.0 and xUnit.net have a few(few)
distinctions.
But only NUnit 3.0 has full documentation.
Whereas our team have been learning yet, we need a lot of
information about using new for us framework.
So according to the requirements I have chosen NUnit 3.0 as
a unit testing framework for our educational project.
CollectionAssert Members has the same elements as Nunit but it is uncategorized
The XUnit Assert class works differently than the one in NUnit. XUnit will throw an exception on an assertion failure, whereas NUnit reports an error to the test execution context.
Parallelism in Test Frameworks
Parallelism in Runners
Parallelism via Configuration
https://github.com/nunit/docs/wiki/Parallelizable-Attribute