[Cache from http://ciips.ee.uwa.edu.au/Research/SCL/Docs/TestSpecGuide.html; please use this canonical URL/source if possible.]
Main Tags
|
Left (test selection) panel of the TPV |
CreditsThe original version of this guide was prepared by Simon Newton. |
There should only be only <TestSet> per file. (This is anticipating a planned change to the specification syntax which will see the <TestSet> become the root element for the document.)
<Constructor Name="class_name"> </Constructor>This will invoke a constructor for class_name for the class your wanting to test.
<MethodCall Name="Method_Name" Target="Target_Object"> </MethodCall>Here Method_Name is the name of the method to call and Target_Object is the object to call the method on.
<MethodCall Name="getVolume" Target="box1"> </MethodCall>
<MethodCall Name="setHeight" Target="box1"> <Arg Name="h" DataType="int">2</Arg> </MethodCall>Naturally you can have more than one argument. Just put them after each other.
<MethodCall Name="getVolume" Target="box1"> <Result Name="volumeOfBox" DataType="int" Save="Y"> </Result> </MethodCall>Now the volume of the box is stored in the variable volumeOfBox which is an int. You can now use this variable in subsequent method calls. If you want to save the result for later use (in addition to checking its type now) you specify a Name for the result and add Save="Y".
<MethodCall Name="getCost" Target="Some_Object"> <Arg Name="volume" Source="volumeOfBox" DataType="int"></Arg> </MethodCall>This is calling the getCost(int volume) method and passing it the volumeOfBox variable.
<MethodCall Name="getVolume" Target="box1"> <Result Name="volumeOfBox" DataType="int"> <Exp>10<Exp> </Result> </MethodCall>Just a note here: if a String is expected, do not put "'s around it. So for a getName() method which returns a String, the test would be:
<MethodCall Name="getName" Target="box1"> <Result Name="box_name" DataType="java.lang.String"> <Exp>box one<Exp> </Result> </MethodCall>One more thing to notice. java.lang.String The TPV requires that you provide the fully qualified class name: these can be found in the standard API for common classes. This also goes for exceptions which are next....
<MethodCall Name="setHeight()" Target="box1"> <Arg Name="h" DataType="int">2</Arg> <Exception Name="e" DataType="java.someException"> <Exp>Height must be Positive<Exp> </Exception> </MethodCall>The bit between the <Exp> tags is the message String that is set when the exception is thrown.
With both results and exceptions,
<Exp>null</Exp>
Array Declaration | Class "Name" |
---|---|
int[] | [I |
int[][] | [[I |
double[] | [D |
double[][] | [[D |
String[] | [Ljava.lang.String; |
Box[] | [LBox; |
So when testing a method:
static int[] makeZeroArray( int n );use:
<MethodCall Name="makeZeroArray" Target="TestArrays" Static="Y"> <Result Name="zero" DataType="[I" Save="Y"></Result> </MethodCall>
addToClass(String[] people)You can use a helper class to create the array and then pass the array over to the method to be tested. This example uses a StringHelper to create an array of Strings an return the array. If you look and the StringHelper class it has a static method which takes a String in which the separate elements of the array are separated by ":" . So the test script is as follows:
<MethodCall Name="makeStringArray"> <Arg Name="Strings" DataType="java.lang.String">Adam:Bevan:Gav:Kyle:Simon</Arg> <Result Name="people" DataType="[Ljava.lang.String;" Save="Y"> </Result> </MethodCall> <MethodCall Name="addToClass" Target="some_target"> <Arg Name="people" Source="people" DataType="[Ljava.lang.String;"></Arg> </MethodCall>
<MethodCall Name="setName" Target="person1"> <Arg Name="name" DataType="java.lang.String">null</Arg> </MethodCall>What your supposed to do if you want to pass it the String "null" I'm not sure, but why you'd want to do that I'm also not sure! You can always add to a Helper class:
public static String makeNull() { return "null"; }