Linking the Executable Test to an Application Test Class


To be able to run this test, we need to provide the assertTrue, assertFalse, and login functions. We could do this right inside each executable test, but then we'd be creating duplication. We want to do this in just one place for every test. The first step is to link this test to where those definitions are going to be. Here's how we do that (the bold text is what we need to add):

 public class LoginStoryTest extends XTrackTest {     public LoginStoryTest(String name) {super(name); }    public void testLogin() {        assertTrue( login("bob","bobspassword") );       assertTrue( login("BOB","bobspassword") );       assertFalse(login("bob","");       assertFalse(login("bob","BOBSPASSWORD") );    } } 

On the first line, we added the phrase extends XTrackTest. This tells the Java compiler that our LoginStoryTest doesn't stand on its own but is actually a variant of another thing called an XTrackTest. This will cause the Java compiler to look in the definition of XTrackTest to find assertTrue, assertFalse, and login, since they aren't defined here in this class.

On the second line, we added a constructor, a special method the JUnit test runner will use to create and run our LoginStoryTest. Other than the name, which always has to be the same as the containing class (LoginStoryTest, in this case), this line will always be the same. It doesn't do anything itself it just calls the constructor in the XTrackTest class (referred to as super).



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