Class MultiTest

java.lang.Object
com.sun.javatest.lib.MultiTest
All Implemented Interfaces:
Test

public class MultiTest extends 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( )
  • Field Details

    • testClass

      protected final Class<?> testClass
    • testArgTypes

      protected static final Class<?>[] testArgTypes
    • log

      protected 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 PrintWriter ref
      Output that can be used as reference.

      Output to this PrintWriter is used during golden file comparison.

    • testMethods

      protected 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 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 Vector<String> excludeTestCases
      The set of test cases to be excluded.
  • Constructor Details

    • MultiTest

      public MultiTest()
  • Method Details

    • run

      public final Status run(String[] argv, PrintStream log, 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:
    • run

      public Status run(String[] argv, PrintWriter log, 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 interface Test
      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

      protected final void decodeAllArgs(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

      protected int decodeArg(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 arguments argv.

      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 line
      index - current index into argv.
      Throws:
      MultiTest.SetupException - raised when an invalid argument is passed, or another error occurred.
      See Also:
    • 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 Method getTestCase(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:
    • invokeTestCase

      protected Status invokeTestCase(Method m) throws IllegalAccessException, InvocationTargetException
      Throws:
      IllegalAccessException
      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:
    • reverse

      public Vector<Method> reverse(Vector<Method> v)
    • init

      protected Status init(String[] argv)
      Deprecated.
      Use decodeArg(String and init() instead.
      Initialize the test from the given arguments.