Class MultiTest
- java.lang.Object
-
- com.sun.javatest.lib.MultiTest
-
- All Implemented Interfaces:
Test
public class MultiTest extends java.lang.Object implements Test
Base class for tests with multiple sub test cases. This base class implements the standard com.sun.javatest.Test features so that you can provide the additional test cases without concern about the boilerplate needed to execute individual test case methods.You must add individual test case methods to your derived test class to create a useful test class. Each test case method must take no arguments. If you need to pass an argument into a test method, you should design a wrapper test case to calculate the argument values and then call the test method with the correct arguments. The test case methods must implement this interface:
public Status methodName( )
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultiTest.SetupException
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector<java.lang.String>
excludeTestCases
The set of test cases to be excluded.protected java.io.PrintWriter
log
Output to be logged to result file.protected java.io.PrintWriter
ref
Output that can be used as reference.protected static java.lang.Class<?>[]
testArgTypes
protected java.lang.String[]
testCases
Deprecated.protected java.lang.Class<?>
testClass
protected java.lang.reflect.Method[]
testMethods
The list of test case methods to be executed.
-
Constructor Summary
Constructors Constructor Description MultiTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
decodeAllArgs(java.lang.String[] argv)
Parses the arguments passed to the test.protected int
decodeArg(java.lang.String[] argv, int index)
Decode the next argument in the argument array.protected void
getAllTestCases()
Generates a list of all test case methods.protected java.lang.reflect.Method
getTestCase(java.lang.String testCase)
Creates a test case method using the name of the method.protected void
init()
A setup method called after argument decoding is complete, and before the test cases are executed.protected Status
init(java.lang.String[] argv)
Deprecated.Use decodeArg(String and init() instead.protected Status
invokeTestCase(java.lang.reflect.Method m)
java.util.Vector<java.lang.reflect.Method>
reverse(java.util.Vector<java.lang.reflect.Method> v)
Status
run(java.lang.String[] argv, java.io.PrintStream log, java.io.PrintStream ref)
Run the test contained in this object.Status
run(java.lang.String[] argv, java.io.PrintWriter log, java.io.PrintWriter ref)
Run the test contained in this object.
-
-
-
Field Detail
-
testClass
protected final java.lang.Class<?> testClass
-
testArgTypes
protected static final java.lang.Class<?>[] testArgTypes
-
log
protected java.io.PrintWriter log
Output to be logged to result file.Output to this PrintWriter is not used during golden file comparison. Also used to output the Status from each individual test case.
-
ref
protected java.io.PrintWriter ref
Output that can be used as reference.Output to this PrintWriter is used during golden file comparison.
-
testMethods
protected java.lang.reflect.Method[] testMethods
The list of test case methods to be executed.An array of test case methods to be executed. It is usually filled up with the values by the decodeArg method.
-
testCases
protected java.lang.String[] testCases
Deprecated.Formerly served as the list of test case methods to be executed.Left for backward compatibility only. Due to be deleted soon.
-
excludeTestCases
protected java.util.Vector<java.lang.String> excludeTestCases
The set of test cases to be excluded.
-
-
Method Detail
-
run
public final Status run(java.lang.String[] argv, java.io.PrintStream log, java.io.PrintStream ref)
Run the test contained in this object.Implements Test.run using reflection to call test methods specified in the testMethods array. Each test method specified in the testMethods array can take no arguments.
This method is a convenience wrapper around the primary run method which takes PrintWriters: this variant takes PrintStreams and wraps them into PrintWriters.
- Parameters:
argv
- Execute arguments passed in from either the command line or the execution harness.log
- Output stream for general messages from the tests.ref
- Output stream for reference output from the tests.- Returns:
- Overall status of running all of the test cases.
- See Also:
decodeAllArgs(java.lang.String[])
,init()
-
run
public Status run(java.lang.String[] argv, java.io.PrintWriter log, java.io.PrintWriter ref)
Run the test contained in this object.Implements Test.run using reflection to call test methods specified in the testMethods array. Each test method specified in the testMethods array can take no arguments.
This method calls the decodeAllArgs method with the value of argv to decode command line arguments, and then calls the init method to perform any other initialization. To add parsing for new arguments you need to override the decodeArg method. The init method may also be overridden in case you need additional initialization.
- Specified by:
run
in interfaceTest
- Parameters:
argv
- Execute arguments passed in from either the command line or the execution harness.log
- Output stream for general messages from the tests. Is assigned to this.log.ref
- Output stream for reference output from the tests. Is assigned to this.ref.- Returns:
- Overall status of running all of the test cases.
- See Also:
decodeAllArgs(java.lang.String[])
,init()
-
decodeAllArgs
protected final void decodeAllArgs(java.lang.String[] argv) throws MultiTest.SetupException
Parses the arguments passed to the test.This method embodies the main for loop for all of the execute arguments. It calls
decodeArg
for successive arguments in the argv array.- Parameters:
argv
- execute arguments from the test harness or from the command line.- Throws:
MultiTest.SetupException
- raised when an invalid parameter is passed, or another error occurred.- See Also:
decodeArg(java.lang.String[], int)
-
decodeArg
protected int decodeArg(java.lang.String[] argv, int index) throws MultiTest.SetupException
Decode the next argument in the argument array. May be overridden to parse additional execute arguments.The default behavior of decodeArg( String argv[], int index ) is to parse test case IDs starting from
index
from execute argumentsargv
.The derived class may override this method to provide parsing of additional arguments. However, it is recommended for this method to return super.decodeArg() if it does not recognize the argument. So it has to parse specific for derived class arguments only.
The required syntax for using this method is the execute argument -TestCaseID followed by a space and then a space delimited list of one or more test case method names. Using the test case method name ALL specifies that all of the individual test case methods that match the required test method signature should be executed. The method getAllTestCases() is called to gather the list of all methods that match the test method signature.
Once the execute argument -TestCaseID is found, all subsequent execute arguments will be treated as test case method names until either the execute argument array is exhausted or an execute argument that begins with - is found.
- Parameters:
argv
- execute arguments from the test harness or from the command lineindex
- current index into argv.- Throws:
MultiTest.SetupException
- raised when an invalid argument is passed, or another error occurred.- See Also:
decodeAllArgs(java.lang.String[])
,testMethods
-
init
protected void init() throws MultiTest.SetupException
A setup method called after argument decoding is complete, and before the test cases are executed. By default, it does nothing; it may be overridden to provide additional behavior.- Throws:
MultiTest.SetupException
- if processing should not continue. This may be due to some inconsistency in the arguments, or if it is determined the test should not execute for some reason.
-
getTestCase
protected java.lang.reflect.Method getTestCase(java.lang.String testCase) throws MultiTest.SetupException
Creates a test case method using the name of the method.This method uses reflection to find the method with given name that implement the standard test case method signature:
public Status methodName( )
If no such method could be found, a SetupException is thrown.
NOTE: You will want to override this method if there are methods in your test class that match the test method signature that should not be executed as part of the test. As an example, see the SerializeTests base class.
- Throws:
MultiTest.SetupException
- raised when no method with given name and signature is found, or another error occurred.- See Also:
decodeArg(java.lang.String[], int)
-
invokeTestCase
protected Status invokeTestCase(java.lang.reflect.Method m) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
getAllTestCases
protected void getAllTestCases() throws MultiTest.SetupException
Generates a list of all test case methods.This method uses reflection to examine all of the public methods of the test class to find those methods that implement the standard test case method signature:
public Status methodName( )
If no methods matching this signature could be found, a SetupException is thrown. If at least one method matching the signature is found, this method assigns that list to the testMethods array.
NOTE: You will want to override this method if there are methods in your test class that match the test method signature that should not be executed as part of the test. As an example, see the SerializeTests base class.
- Throws:
MultiTest.SetupException
- raised when no methods matching the test method signature is found, or another error occurred.- See Also:
testMethods
-
reverse
public java.util.Vector<java.lang.reflect.Method> reverse(java.util.Vector<java.lang.reflect.Method> v)
-
init
protected Status init(java.lang.String[] argv)
Deprecated.Use decodeArg(String and init() instead.Initialize the test from the given arguments.
-
-