202 pdfsam Foundations Of Ajax (2005)

CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT Figure 6-10. Setting the trace level Figure 6-11. The trace output Running...

0 downloads 86 Views 189KB Size
CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT

Figure 6-10. Setting the trace level

Figure 6-11. The trace output

Running Tests Now that you’ve written some tests, you need to run them, and to do this you can use the JsUnit test runner. You’ve already seen lots of examples of firing the test runner, but how do you do this? To access the runner, point your target browser to the testRunner.html file found in the jsunit folder. The test runner looks like Figure 6-12. The test runner is fairly similar to the graphical runners that are often used in the JUnit space. (However, interestingly, the hotly awaited JUnit 4 does not include a graphical test runner, and one is not expected to be added.) To run a test, you select the file to run by clicking Choose File. As you would expect, the progress bar remains green, as shown in Figure 6-13, until the test runner encounters a failure. The Runs field indicates the total number of test functions; any errors or failures will also be reported. An error comes from the browser and indicates that something was wrong with the test page, and a failure indicates one of your asserts actually failed. The specific error or failure will be displayed in the Errors and Failures text box; to see more details about the error or failure, double-click the test function in question. Alternatively, highlight it, and select Show Selected. In the event of a failure, an alert will display the expected and actual values plus any message you added to your assert. If you’re seeing an error, the message will (probably) help you narrow down what is wrong.

179