After creating the test
application, it is time to execute. There are few ways of doing it but the most
common way is, choose Test => Run => All Tests just like shown in Figure 1. Another way is, right click
on any code page or test method and select Run Tests just like shown in Figure
2.
Figure 1. Running all test cases
using Test menu option
Figure 2. Running test cases using context menu of
code file
Either option runs the test methods (annotated with [TestMethod]). Also,
the Test Explorer window opens just like shown in Figure 3, displaying status
and results of test methods:
Figure 3. Test Explorer window showing
successful tests
In Figure 3 above, the
status of the test cases is “Passed” designated by white check inside the green
circle. When any test gets fail (ex: by changing message expected in ViewBag in the Index() test method), it is labeled
with white cross (X) inside red circle just like shown in Figure 4. A test may
fail due to any reasons:
• Return values of the method is incorrect (per
our Assert statements).
• The output parameters are
incorrect.
• Any expected result did not
occur
• Any bug exists in test code
Figure 4. Test Explorer window showing failed test
To see example fail test in
Index()
test
method of the HomeControllerTest class, change
expected string which
represents the value in the ViewBag.Message property and then compile the application and run tests again.
Clicking on Run link under
Test Explorer window gives more granular options to run the tests just like
shown in Figure 5 below:
Figure 5. Options to run tests with
the Run link
No comments:
Post a Comment