SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 47 | Next

Jonathan Jacky, Margus Veanes, Colin Campbell, Wolfram Schulte

"Model-Based Software Testing and Analysis with C#"

Convert32 tests a very brief run
comprising a single method call. Its body is a single line:
Assert.AreEqual(Temperature.ConvertToCelsius(32), 0);
We happen to know that 32?—¦F (the freezing point of water) corresponds to 0?—¦C;
this test method checks that the ConvertToCelsius method computes the conversion
correctly for this case. The assertion here acts as the oracle, the authority that
provides the correct result to determine whether the test passed or failed.
A test method can make several method calls and check several assertions, so
it can test a run that is longer than a single method call. Our ConvertMany method
checks a few other well-known conversions. Its body is several lines:
Assert.AreEqual(Temperature.ConvertToCelsius(32), 0);
Assert.AreEqual(Temperature.ConvertToCelsius(98.6), 37);
Assert.AreEqual(Temperature.ConvertToCelsius(212), 100);
Assert.AreEqual(Temperature.ConvertToCelsius(212), 101); // Fail!
If any assertion in a test method fails, the test runner considers that test a failure.
Here we have deliberately put an incorrect assertion at the end of the test, in order to
demonstrate how NUnit indicates test failures. This is the cause of the test failure we
observed in the previous section. It also makes the point that a test failure does not
necessarily indicate that the IUT is defective. It might be the test that is defective!
The ConvertToCelsius method is an ideal subject for unit testing because it
gets all the information it needs from its argument (the temperature in Fahrenheit)
and provides all of the information it computes in its return value (the temperature
in Celsius).


Pages:
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6