Skip to main content

Compares popular .NET Unit Test Frameworks usages with their respective counterparts.

---
title: .NET Unit Test Framework Translation Cheatsheet
subtitle: Compares popular .NET Unit Test Frameworks usages with their respective counterparts.
date: January 27, 2021
source: https://www.automatetheplanet.com/mstest-cheat-sheet/
snippet: https://jonlabelle.com/snippets/view/markdown/net-unit-test-framework-translation-cheatsheet
gist: https://gist.github.com/jonlabelle/9afa182a1ecc2bfaac42a6586e45f292
notoc: true
---

## Attributes

|      NUnit 3.x       |     MSTest v2.x      |       xUnit.net 2.x       |                      Comments                      |
|----------------------|----------------------|---------------------------|----------------------------------------------------|
| `[Test]`             | `[TestMethod]`       | `[Fact]`                  | Marks a test method.                               |
| `[TestFixture]`      | `[TestClass]`        | n/a                       | Marks a test class.                                |
| `[SetUp]`            | `[TestInitialize]`   | `Constructor`             | Triggered before every test case.                  |
| `[TearDown]`         | `[TestCleanup]`      | `IDisposable.Dispose`     | Triggered after every test case.                   |
| `[OneTimeSetUp]`     | `[ClassInitialize]`  | `IClassFixture<T>`        | One-time triggered method before test cases start. |
| `[OneTimeTearDown]`  | `[ClassCleanup]`     | `IClassFixture<T>`        | One-time triggered method after test cases end.    |
| `[Ignore("reason")]` | `[Ignore]`           | `[Fact(Skip="reason")]`   | Ignores a test case.                               |
| `[Property]`         | `[TestProperty]`     | `[Trait]`                 | Sets arbitrary metadata on a test.                 |
| `[Theory]`           | `[DataRow]`          | `[Theory]`                | Configures a data-driven test.                     |
| `[Category("")]`     | `[TestCategory("")]` | `[Trait("Category", "")]` | Categorizes the test cases or classes.             |

## Assertions

|   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                   | n/a                | 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.              |

> Original from [*Automate The Planet: Most Complete MSTest Unit Testing Framework Cheat Sheet*](https://www.automatetheplanet.com/mstest-cheat-sheet/#tab-con-6), which was taken from [*Comparing xUnit.net to other frameworks*](https://xunit.net/docs/comparisons).