Improving the Customer Acceptance Test


However, while working through this, we found a bit of a difficulty. Each customer test is in a file. The files are looped over in the CustomerTest.cs class. Each test consists of executing some commands and then doing a *output command, which compares the current contents of the model with the expected value provided. The comparison was being done with a simple Assert, like this:

 private void CompareOutput(StringReader reader, String message) { 
String expected = ExpectedOutput(reader);
String result = model.TestText;
AssertEquals(message, expected, model.TestText);
}

NUnit isn t much help here. The test shows up as a failure in CustomerTest.cs and doesn t really show what happened clearly. You can sort of scroll through the output in NUnit s little window, but it s not very clear. So we improved the CustomerTest CompareOutput method:

 private void CompareOutput(StringReader reader, String message) { 
String expected = ExpectedOutput(reader);
String result = model.TestText;
if (expected != result) {
Console.WriteLine(message);
Console.WriteLine("*Expected");
Console.WriteLine(expected);
Console.WriteLine("*Result");
Console.WriteLine(result);
}
AssertEquals(message, expected, model.TestText);
}

Now, when a test fails, NUnit s StandardOut window looks like this, showing us just what happened:

click to expand



Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net