Running the Test


Whew! We're done making this test run. It may seems like a lot when you go through it line by line like this, but if you take a look back over what we've done, you'll see that we've just written (or modified) about twelve lines of Java code. This will take about fifteen minutes, perhaps less, once you get the hang of it.

We can now compile and run LoginStoryTest, assuming that the code for the JUnit framework and the parts of the XTrack system are in the place we specified.

The tests are compiled just like any other Java program, using the Java compiler (javac):

 javac LoginStoryTest.java  

Because LoginStoryTest.java references XTrackStory (in the extends clause), compiling LoginStoryTest.java will also compile XTrackTest.java.

The tests are run using the Java interpreter (java) and a utility from the JUnit framework named TestRunner. TestRunner has two flavors: a command-line version and a GUI version. The GUI version is run as follows:

 java junit.swingui.TestRunner LoginStoryTest  

When all the tests pass, the result looks like Figure 22.1.

Figure 22.1. Result of all tests passing the GUI version

graphics/22fig01.gif

The command-line version runs the tests in the same manner, but it displays the results in a textual format and terminates when the tests are run (unlike the GUI version, which hangs around until you explicitly click the Exit button). You run it like this:

 java junit.textui.TestRunner LoginStoryTest  

When all the test pass in this version, it looks like this:

 .Time: 0.01  OK (1 tests) 


Testing Extreme Programming
Testing Extreme Programming
ISBN: 0321113551
EAN: 2147483647
Year: 2005
Pages: 238

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net