Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jonlabelle/9afa182a1ecc2bfaac42a6586e45f292 to your computer and use it in GitHub Desktop.
Save jonlabelle/9afa182a1ecc2bfaac42a6586e45f292 to your computer and use it in GitHub Desktop.
.NET Unit Test Framework Translation Cheatsheet
title subtitle date source snippet gist notoc
.NET Unit Test Framework Translation Cheatsheet
Compares popular .NET Unit Test Frameworks usages with their respective counterparts.
January 27, 2021
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, which was taken from Comparing xUnit.net to other frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment