|
C# 2008 Programmer's ReferenceMethods with that attribute are known as test methods. Now modify the implementation of the lengthTest() method to basically create and initialize two Point objects and then call the length() method of the Point class to calculate the distance between the two points: /// <summary> ///A test for length ///</summary> [TestMethod()] public void lengthTest() { int x = 3; int y = 4; Point target = new Point(x, y); Point pointOne = new Point(0,0); double expected = 5F; double actual; actual = target.length(pointOne); Assert.AreEqual(expected, actual, "UnitTesting.Point.length did not return the expected value."); } Once the result is returned from the length() method, you use the AreEqual() method from the Assert class to check the returned value against the expected value. If the expected value does not match the returned result, the error message set in the AreEqual() method is displayed. Running the Test Before you run the unit test, take a look at the Test Tools toolbar (see Figure 2-73) automatically shown in Visual Studio 2008 ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|