205 pdfsam Foundations Of Ajax (2005)

182 CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT Figure 6-15. Error details Failures look the same in the runner (they ...

0 downloads 18 Views 238KB Size
182

CHAPTER 6 ■ TESTING JAVASCRIPT WITH JSUNIT

Figure 6-15. Error details

Failures look the same in the runner (they result in a red bar), but the details are different. For those familiar with JUnit, the failure information will look downright familiar. Let’s return to your test with the simpleJS.js file. Pretend that you expect 2 + 2 to equal 5, as shown in Listing 6-11, and see what happens. Listing 6-11. Another Deliberate Mistake function testValidArgs() { assertEquals("we really do know that 2 + 2 is 4", 5, addTwoNumbers(2, 2)); } As you would expect, the test runner will show a red bar, but the detail alert is a bit different, as shown in Figure 6-16. The details of the failure are quite helpful, as shown in Figure 6-17. You see any message that you entered in the assert function, and you get the expected and actual values along with a stack trace that shows you where the failure occurred. At this point, we’ve talked about every field in the test runner except two: Page Load Timeout and Setup Page Timeout. The Page Load Timeout field deals with how patient the test runner will be with your test page—if your page takes longer than the number in this box (expressed in seconds), the test runner will throw an error that looks like Figure 6-18. If you see this error, make sure your test page is actually a test page. (In other words, make sure you’ve included the jsUnitCore.js file, make sure the path statement is correct, and if you’re accessing the page across the network, make sure it’s available.) Of course, if you are doing distributed testing, you may need to increase the time in the Page Load Timeout field!