UNIT TESTING FRAMEWORKS

Unit-testing frameworks are like a good pair of work boots. You hate them at first because they are uncomfortable, but the more you wear them, the more you start to love them. By the time you have to get a new pair of boots, or a new testing framework in this case, you start to complain again because it's uncomfortable. Unit-testing frameworks tend to cause the most religious wars between the different testing tools.

MSTest

MSTest is the testing framework created by Microsoft that has been included in specific versions of Visual Studio since 2005. MSTest sparks many heated discussions among developers. When all is said and done, MSTest is similar to many of the other unit-testing frameworks, with a slightly different syntax. It has been my experience that the tests run slower, but you should make your own call.

The syntax for MSTest is much like that for NUnit, except that the Test Fixture has a TestClass attribute, and the actual tests have a TestMethod attribute:

images
[TestClass]
public class HTMLHelpersTests
{
    [TestMethod]
    public void Should_Truncate_Text_Over_Five_Characters_Long()
    {
 string textToTruncate = “This is my text”; string expected = “This ..”; string actual = HTMLHelper.Truncate(textToTruncate, 5); Assert.AreEqual(expected, actual); } [TestMethod] public void Should_Not_Truncate_Text_When_No_Length_Is_Passed_In() { string textToTruncate = “This ...

Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.