O'Reilly logo

Professional Test-Driven Development with C#: Developing Real World Applications with TDD by Jeff McWherter, James Bender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required