ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

junitutils
Class TestFilesTestSuite

java.lang.Object
  extended byjunit.framework.TestSuite
      extended byjunitutils.TestFilesTestSuite
All Implemented Interfaces:
junit.framework.Test

public class TestFilesTestSuite
extends junit.framework.TestSuite

This is a JUnit TestSuite that is created from a number of tests as follows. Each TestCase is an instance of the inner class Helper, instantiated with a name of a file. The file names are read from the file named by the parameter 'fileOfTestFilenames'. The argument to the constructor named 'args' provides a set of command-line arguments; the filename for the TestCase is added on to the end of the list of command-line arguments. Then the static compile method of the given class is called on those command-line arguments.

The standard output and error output is captured from the execution of the compile method. This is compared to the output in filename + "-expected". The TestCase succeeds if these match; if they do not match, the test fails and the actual output is saved in filename + "-ckd".

The test must be run from the directory in which it resides - because it creates and opens files in the current directory.

Author:
David R. Cok

Nested Class Summary
 class TestFilesTestSuite.Helper
          This is a helper class that is actually a TestCase; it is run repeatedly with different constructor arguments.
 
Field Summary
protected  java.lang.reflect.Method method
          The method that is to be executed on the command-line arguments.
(package private) static java.lang.String ORACLE_SUFFIX
           
(package private) static java.lang.String SAVED_SUFFIX
           
protected  java.lang.String testName
          The name of this test suite.
 
Fields inherited from class junit.framework.TestSuite
 
Constructor Summary
protected TestFilesTestSuite()
           
  TestFilesTestSuite(java.lang.String testName, java.lang.String fileOfTestFilenames, java.lang.String[] args, java.lang.Class cls)
          A constructor for this test suite.
 
Method Summary
 java.lang.String checkReturnValue(java.lang.String fileToTest, java.lang.String expectedOutput, java.lang.Object returnedValue)
           
protected  java.lang.String doOutputCheck(java.lang.String fileToTest, java.lang.String output, java.lang.Object returnedValue)
           
protected  java.lang.Object dotest(java.lang.String fileToTest, java.lang.String[] args)
          This is the actual test; it compiles the given file and compares its output to the expected result (in fileToTest+ORACLE_SUFFIX); the output is expected to match and the result of the compile to be true or false, depending on whether errors or warnings were reported.
 boolean expectedBooleanStatus(java.lang.String fileToTest, java.lang.String expectedOutput)
           
 int expectedIntegerStatus(java.lang.String fileToTest, java.lang.String expectedOutput)
           
 java.lang.String expectedStatusReport(java.lang.String fileToTest, boolean b, java.lang.String expectedOutput)
           
 java.lang.String expectedStatusReport(java.lang.String fileToTest, int ecode, java.lang.String expectedOutput)
          Returns null if ok, otherwise returns failure message.
protected  TestFilesTestSuite.Helper makeHelper(java.lang.String filename, java.lang.String[] args)
          Factory method for the helper class object.
 
Methods inherited from class junit.framework.TestSuite
addTest, addTestSuite, countTestCases, createTest, getName, getTestConstructor, run, runTest, setName, testAt, testCount, tests, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

testName

protected java.lang.String testName
The name of this test suite.


method

protected java.lang.reflect.Method method
The method that is to be executed on the command-line arguments.


SAVED_SUFFIX

static final java.lang.String SAVED_SUFFIX
See Also:
Constant Field Values

ORACLE_SUFFIX

static final java.lang.String ORACLE_SUFFIX
See Also:
Constant Field Values
Constructor Detail

TestFilesTestSuite

protected TestFilesTestSuite()

TestFilesTestSuite

public TestFilesTestSuite(java.lang.String testName,
                          java.lang.String fileOfTestFilenames,
                          java.lang.String[] args,
                          java.lang.Class cls)
A constructor for this test suite.

Parameters:
testName - The name of the test suite
fileOfTestFilenames - The file to be read for filenames of tests
args - The command-line arguments that the static compile method will be applied to, with the filename added on
cls - The class in which to find the static compile method
Method Detail

makeHelper

protected TestFilesTestSuite.Helper makeHelper(java.lang.String filename,
                                               java.lang.String[] args)
Factory method for the helper class object.


dotest

protected java.lang.Object dotest(java.lang.String fileToTest,
                                  java.lang.String[] args)
                           throws java.lang.IllegalAccessException,
                                  java.lang.IllegalArgumentException,
                                  java.lang.reflect.InvocationTargetException
This is the actual test; it compiles the given file and compares its output to the expected result (in fileToTest+ORACLE_SUFFIX); the output is expected to match and the result of the compile to be true or false, depending on whether errors or warnings were reported. Override this method in derived tests.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException

doOutputCheck

protected java.lang.String doOutputCheck(java.lang.String fileToTest,
                                         java.lang.String output,
                                         java.lang.Object returnedValue)

checkReturnValue

public java.lang.String checkReturnValue(java.lang.String fileToTest,
                                         java.lang.String expectedOutput,
                                         java.lang.Object returnedValue)

expectedStatusReport

public java.lang.String expectedStatusReport(java.lang.String fileToTest,
                                             int ecode,
                                             java.lang.String expectedOutput)
Returns null if ok, otherwise returns failure message.


expectedStatusReport

public java.lang.String expectedStatusReport(java.lang.String fileToTest,
                                             boolean b,
                                             java.lang.String expectedOutput)

expectedBooleanStatus

public boolean expectedBooleanStatus(java.lang.String fileToTest,
                                     java.lang.String expectedOutput)

expectedIntegerStatus

public int expectedIntegerStatus(java.lang.String fileToTest,
                                 java.lang.String expectedOutput)

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage