Skip to content

Instantly share code, notes, and snippets.

@ssg
Last active March 13, 2017 08:19
Show Gist options
  • Save ssg/5329684 to your computer and use it in GitHub Desktop.
Save ssg/5329684 to your computer and use it in GitHub Desktop.
MBUnit <-> NUnit migration cheat sheet.

This is a cheat sheet I prepared when testing migrations between MBUnit and NUnit. It only covers the areas we used so it's far from complete. It should give a good head start though.

MBUnit NUnit
[FixtureSetUp] [OneTimeSetUp]
[Row] [TestCase]
[Factory] [TestCaseSource] for test cases, [ValueSource] for individual parameters
[Column] [Values]
[SequentialJoin] [Sequential]
[CombinatorialJoin] [Combinatorial]
Assert.IsInstanceOfType<T>(y) Assert.IsInstanceOf<T>(y)
Assert.AreElementsEqual(coll, expectedColl) CollectionAssert.AreEqual(expectedColl, coll)
Assert.AreElementsEqualIgnoringOrder(coll, expectedColl) CollectionAssert.AreEquivalent(expectedColl, coll)
Assert.AreElementsSame(expectedColl, coll) CollectionAssert.AreEqual(expectedColl, coll) ???
Assert.AreEqual(coll, expectedColl) CollectionAssert.AreEqual(expectedColl, coll)
Assert.Contains(coll,item) CollectionAssert.Contains(coll, item)
Assert.DoesNotContain(coll,item) CollectionAssert.DoesNotContain(coll, item)
Assert.IsEmpty(coll) CollectionAssert.IsEmpty(coll)
Assert.IsEmpty(str) Assert.That(str, Is.Empty)
Assert.StartsWith(str, substr) StringAssert.StartsWith(substr, str)
Assert.EndsWith(str, substr) StringAssert.EndsWith(substr, str)
Assert.Contains(str, substr) StringAssert.Contains(substr, str)
Assert.DoesNotContain(str, substr) StringAssert.DoesNotContain(substr, str)
Assert.AreEqual(expected, result, new StructuralEqualityComparer) Assert.That(result, Is.EqualTo(expected).Using(new Comparer())
Assert.LessThanOrEqualTo(x,y) Assert.LessOrEqual(x, y)
Assert.LessThan(x,y) Assert.Less(x, y)
Assert.GreaterThan(x,y) Assert.Greater(x, y)
Assert.GreaterThanOrEqualTo(x,y) Assert.GreaterOrEqual(x, y)
Assert.ForAll(coll, item => code) Assert.IsFalse(coll.Any(item => !code))
Assert.Between(modifiedDate, new DateTime(2014, 01, 01), new DateTime(2999, 01, 01)) Assert.That(modifiedDate, Is.InRange(new DateTime(2014, 01, 01), new DateTime(2999, 01, 01)))
Assert.AreApproximatelyEqual(expectedDate, actualDate, TimeSpan.FromSeconds(5)) Assert.That(actualDate, Is.EqualTo(expectedDate).Within(5).Seconds);
@ssg
Copy link
Author

ssg commented Jan 29, 2016

thanks folks. i updated some of these.

@ssg
Copy link
Author

ssg commented Jan 29, 2016

@nickbeaugie ExpectedException was deprecated in NUnit 3 IIRC fyi.

@outring
Copy link

outring commented Jun 22, 2016

Assert.ForAllAssert.That(collection, Has.All.Matches<SomeType>(item => code))
Assert.ExistsAssert.That(collection, Has.Some.Matches<SomeType>(item => code))
Assert.DoesNotExistAssert.That(collection, Has.None.Matches<SomeType>(item => code))

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