Running Unit Tests

When you create unit tests, Visual Studio automatically shows and anchors the Test Tools toolbar that contains buttons for executing, debugging, and managing unit tests. You can choose to run a single unit test or multiple ones. For the current example, click the Run All Tests in Solution button. When all unit tests complete, the Test Results tool window shows a report about test success or failures. Figure 59.2 shows how such a window looks for the current example.

Figure 59.2 Viewing unit test results.

image

Notice how the CalculateAreaTest method failed while CalculatePerimeterTest succeeded. The Error Message column provides details on the occurred error so that you can fix it. In this case the equality check failed because the method returned a result different from the expected one. You can also get detailed failure information, by clicking the Test Run Failed hyperlink. Figure 59.3 shows the failure summary, where you can get information on the test name, server, and timestamp.

Figure 59.3 Viewing the test failure summary.

image

Note on Fixing Errors

In a typical real-life scenario, you will not edit the expected result to make a unit test work, whereas you will instead fix errors in the code. The example proposed in this chapter is a demo scenario, and its purpose is explaining how unit test works. This is the reason why here you are about to fix the expected result, but in real-world applications the expected result will remain unvaried.

In the CalculateAreaTest method, replace the expected declaration as follows:

Dim expected As Double = 200

Now run again both unit tests. At this point both tests pass because in both cases expected value and actual value are equal, as demonstrated in Figure 59.4.

Figure 59.4 Both unit tests passed.

image

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.27.58