Combining Multiple Tests into Test Suites


Now that we have these two executable tests running (logging in, maintaining user ids), we could manually run them one after another, but that would quickly become tiresome as we get more and more of the tests running.

A better way is to create a test suite that combines all the tests, so we can run them in a single operation. Listing 22.4 shows an example that illustrates this by defining a test suite with the LoginStoryTest and UserIdStoryTest, in a class named AllTests.

Listing 22.4 AllTests.java
 import junit.framework.*; public class AllTests {       public static Test suite ( ) {          TestSuite suite= new TestSuite("XTrack");          suite.addTest(                 new TestSuite(LoginStoryTest.class));          suite.addTest(               new TestSuite(UserIdStoryTest.class));           return suite;       } } 

The beginning and end sections of this file can always be the same; it's the text marked in bold that includes LoginStoryTest and UserIdStoryTest in the suite. As you get each executable test running, you add it to the suite by adding lines like this to AllTests.

For instance, to add the tests for the story about adding, updating, and displaying tasks (TaskStoryTest), you'd add the following line:

 suite.addTest(new TestSuite(TaskStoryTest.class));  

By continuing in this fashion, you can get the entire set of executable tests running and build a suite in AllTests.java that runs all the tests with a single operation.

In the next chapter, we'll show you how to take these same tests and run them through the user interface instead of calling the individual pieces of the system directly. That'll make for a more realistic end-to-end test.



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