Creating a Tool-Specific Interface Class


The final step is to define XTrackWebARTInterface, which will hold the new methods we'll write to interface to XTrack using the WebART tool. Exactly what these new methods do depends on how you need to interface to a particular tool.

Unfortunately, there's no free lunch. While the direct-call method requires exact knowledge of the system code, the test-tool method requires expert knowledge of that test tool. You need to know not just how to use the tool but how to interact with the tool from the language of the executable tests in this case, Java.

One of the reasons we picked WebART for this illustration is that a Java package is available (jWebART) that makes the interface to the tool fairly painless (although it's still necessary to know how to use WebART itself to drive the system). Using jWebART, XTrackWebARTInterface looks like Listing 23.4.

Listing 23.4 XTrackWebARTInterface
 import jWebART.*; public class XTrackWebARTInterface              extends XTrackTestInterface {   public XTrackWebARTInterface() {      super();      project = new WebARTProject("XTRACK");      script = new           WebARTPersistentScript(project,"XTRACKIF");   }   public boolean login( String id,String psw) {        return script.invoke("login","psw=" + psw);   }   public boolean createUserId( String id, String psw,                                String email) {         return script.invoke("createUserId",                              "psw=" + psw,                              "email=" + email);   }   public boolean deleteUserId( String id) {         return script.invoke("deleteUserId",                              "docText">Starting with the first line, the import jWebART.*; statement tells the Java compiler where to find the code for interfacing to WebART in Java. Next, the XTrackWebARTInterface class is defined as extending the XTrackTestInterface class. This is just like the XTrackDirectInterface class.

If you're wondering why we defined XTrackTestInterface and then based the two real interfaces on it, it's so we can store either one in testInf in XTrackTest. We can do this because they share a common base class. Otherwise, we'd have to have two different variables and duplicate code to call the methods of one or the other.

The next thing is the constructor for this class. The code following the call to super essentially does the following:

  • Starts the WebART tool

  • Tells WebART to put into effect a preexisting group of settings (preferences, file paths, options, and so on) named XTRACK

  • Tells WebART to start a script running named XTRACKIF

In other words, if this interface is instantiated (XTrackTest.setTestInterface is called with a value of webart), it will start WebART, set the project to XTRACK, and start the XTRACKIF script. Of course, the XTRACK project and the XTRACKIF script will have to already exist, and we'll have to take care of that within the WebART tool itself.

Finally, we have the login, createUserId, and deleteUserId methods. These call the invoke method in the WebARTPersistentScript object to pass their arguments to a subscript in the XTRACKIF script. The first parameter of invoke is the name of the subscript, and subsequent parameters are the names and values of the parameters to be passed to the subscript.

At this point, we've completed interfacing our tests with the WebART tool. If we compile all our tests again, they'll still go through the direct interface because of the setTestInterface("direct"); in XTrackTest. It would be good practice to do that and make sure the tests all still pass before going on.

Now we change XTrackTest to setTestInterface("webart"); , recompile it, and all the same tests now go to the WebART tool. Most of them fail, because we haven't done any work in WebART to set up the XTRACK project or create the XTRACKIF script. The next chapter will show you how to do that.

Don't worry, things will get easier. We'll start our downhill run pretty soon!



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