net.groboclown.junit.v1
Class RunJarTests

java.lang.Object
  |
  +--net.groboclown.junit.v1.RunJarTests

public class RunJarTests
extends Object

A new way to start JUnit tests. It searches each given Jar file for classes that have a method of the form:

      public static Test suite()
  

Accepts arguments as thus:

      net.groboclown.junit.v1.RunJarTests [options] jar1 [jar2 [jar3 ...] ]
  
where options are:
-h | /h | -? | /? | ?
Display the help page
-x {prefix}
omit the Jar parsing of packages starting with {prefix}.
-runner {classname}
uses the {classname} as the test runner class (defaults to junit.textui.TestRunner). The class must have a method signature of:
          public static void run( junit.textui.TestRunner t, java.io.PrintStream w )
          
or
              public static void run( junit.textui.TestRunner t )
          
If the runner wishes to quit with an exit code, it must handle that itself.

Restriction: must be compilable from JDK 1.1.


Inner Class Summary
private  class RunJarTests.ClasspathIdentifier
           
 
Field Summary
private static String CLASS_EXTENSION
           
private static ExtensionFilenameFilter CLASS_FILTER
           
private  RunJarTests.ClasspathIdentifier[] CP_ID_LIST
           
private  Vector m_cpSearch
           
private  Vector m_ignorePrefix
           
private  PrintStream m_out
           
private  String m_testRunner
           
private  boolean m_wait
           
 
Constructor Summary
RunJarTests(String[] args)
          Standard constructor.
 
Method Summary
(package private) static void ()
           
protected  junit.framework.TestSuite createTestSuite(junit.framework.Test[] tests)
           
protected  String filename2classname(String fullName, String baseName)
          Convert a relative file name into a class name.
protected  void findClasses(String cpElement, Vector suiteList)
          Discovers all Class files from the given CP element, and returns the valid ones' test suites.
protected  junit.framework.Test findTest(Class c)
          Checks the class instance for the public static Test suite() method.
protected  boolean isIgnored(String className)
           
protected  Class loadClass(String className, String cpElement)
          Discover the class element with the given class name, and the given ClassPath element.
protected  junit.framework.Test[] loadTests()
          Loads the classes for all the known CP elements
static void main(String[] args)
          Called from the command line.
protected  void parseCommandLineArguments(String[] args)
          Load up the internal options from the command line arguments.
protected  void runTestRunner(junit.framework.Test test)
           
 void setOutput(PrintStream ps)
          Sets the output for the TestRunner invoked (if it allows one).
protected  void showHelp(int exitCode)
           
 void start()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_cpSearch

private Vector m_cpSearch

m_ignorePrefix

private Vector m_ignorePrefix

m_wait

private boolean m_wait

m_testRunner

private String m_testRunner

m_out

private PrintStream m_out

CLASS_EXTENSION

private static final String CLASS_EXTENSION

CLASS_FILTER

private static final ExtensionFilenameFilter CLASS_FILTER

CP_ID_LIST

private final RunJarTests.ClasspathIdentifier[] CP_ID_LIST
Constructor Detail

RunJarTests

public RunJarTests(String[] args)
Standard constructor.
Method Detail

main

public static void main(String[] args)
Called from the command line.
Parameters:
args - the command line arguments

static void ()

start

public void start()

setOutput

public void setOutput(PrintStream ps)
Sets the output for the TestRunner invoked (if it allows one). Does not currently redirect the test's stdout or stderr.

loadTests

protected junit.framework.Test[] loadTests()
Loads the classes for all the known CP elements

findClasses

protected void findClasses(String cpElement,
                           Vector suiteList)
Discovers all Class files from the given CP element, and returns the valid ones' test suites.

findTest

protected junit.framework.Test findTest(Class c)
Checks the class instance for the public static Test suite() method. If it exists, then the indicated test instance is returned.

parseCommandLineArguments

protected void parseCommandLineArguments(String[] args)
Load up the internal options from the command line arguments.

showHelp

protected void showHelp(int exitCode)

loadClass

protected Class loadClass(String className,
                          String cpElement)
Discover the class element with the given class name, and the given ClassPath element. The class name could be the physical file name (it must end with ".class").

filename2classname

protected String filename2classname(String fullName,
                                    String baseName)
Convert a relative file name into a class name.

createTestSuite

protected junit.framework.TestSuite createTestSuite(junit.framework.Test[] tests)

isIgnored

protected boolean isIgnored(String className)

runTestRunner

protected void runTestRunner(junit.framework.Test test)
Returns:
the static method which takes a Test instance as its argument to start the test, or null if it is not a valid runner.


Written under the LGPL