j2meunit.midletui
Class TestRunner

java.lang.Object
  |
  +--javax.microedition.midlet.MIDlet
        |
        +--j2meunit.midletui.TestRunner
All Implemented Interfaces:
TestListener
Direct Known Subclasses:
ExampleTestMidlet

public class TestRunner
extends javax.microedition.midlet.MIDlet
implements TestListener

A TestRunner that runs as a MIDlet. It can be used in two ways:

Version:
$Revision: 1.5 $
Author:
$author$

Field Summary
protected  javax.microedition.lcdui.StringItem aErrorInfo
           
protected  javax.microedition.lcdui.StringItem aFailureInfo
           
protected  javax.microedition.lcdui.Gauge aProgressBar
           
protected  TestResult aResult
           
protected  javax.microedition.lcdui.List aResultsList
           
protected  java.io.PrintStream aWriter
           
protected  boolean bScreenOutput
           
protected  boolean bTextOutput
           
protected  int nCount
           
protected static TestRunner theInstance
           
 
Constructor Summary
TestRunner()
          Creates a new TestRunner object.
 
Method Summary
 void addError(Test test, java.lang.Throwable t)
          TestListener.addError() - will print 'E' to System.out.
 void addFailure(Test test, AssertionFailedError e)
          TestListener.addError() - will print 'F' to System.out.
 void addToResultsList(java.lang.String sText)
          Add a string to the result output.
 void addToResultsList(java.lang.Throwable t)
          Add a string to the result output.
protected  Test createTestSuite(java.lang.String[] rTestCaseClasses)
          Builds a test suite from all test case classes in a string array.
protected  void destroyApp(boolean bUnconditional)
          Empty implementation of MIDlet.destroyApp.
protected  void doRun(Test suite)
          Will run all tests in the given test suite.
 void endTest(Test test)
          TestListener.endTest()
 void endTestStep(Test test)
          TestListener.endTestStep()
static TestRunner getInstance()
          To return the current TestRunner instance.
protected  javax.microedition.lcdui.List getResultsList()
          Returns the javax.microedition.lcdui.List instance to append the result data to.
 java.io.PrintStream getWriter()
          Get the output stream (defaults to System.out).
protected  void pauseApp()
          Empty implementation of MIDlet.pauseApp.
 void print(TestResult result)
          Prints errors and failures to the standard output
 void printErrors(TestResult result)
          Prints the errors to the standard output
 void printFailures(TestResult result)
          Prints failures to the standard output
 void printFooter()
          Prints the footer
 void printHeader(TestResult result)
          Prints the header of the report
 void setOutputMode(boolean bScreen, boolean bText)
          To set the output mode(s) for this TestRunner.
 void setWriter(java.io.PrintStream aStream)
          Set the output stream.
 void showResult()
          To display the result of the test in a javax.microedition.lcdui.List screen.
protected  void start(java.lang.String[] rTestCaseClasses)
          Starts a test run. processes the command line arguments and creates a test suite from it.
protected  void startApp()
          Default implementation that reads the attribute J2MEUnitTestClasses with getAppProperty and invokes the method start() with the result string.
 void startTest(Test test)
          TestListener.startTest() - will print '.' to te System.out.
 
Methods inherited from class javax.microedition.midlet.MIDlet
getAppProperty, notifyDestroyed, notifyPaused, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theInstance

protected static TestRunner theInstance

aProgressBar

protected javax.microedition.lcdui.Gauge aProgressBar

aResultsList

protected javax.microedition.lcdui.List aResultsList

aWriter

protected java.io.PrintStream aWriter

aErrorInfo

protected javax.microedition.lcdui.StringItem aErrorInfo

aFailureInfo

protected javax.microedition.lcdui.StringItem aFailureInfo

aResult

protected TestResult aResult

bScreenOutput

protected boolean bScreenOutput

bTextOutput

protected boolean bTextOutput

nCount

protected int nCount
Constructor Detail

TestRunner

public TestRunner()
Creates a new TestRunner object.

Method Detail

getInstance

public static TestRunner getInstance()
To return the current TestRunner instance. This is needed to determine the current Display and is only valid after the constructor of TestRunner has been invoked.

Returns:

setOutputMode

public void setOutputMode(boolean bScreen,
                          boolean bText)
To set the output mode(s) for this TestRunner.

Parameters:
bScreen - If TRUE, output will be written to an LCDUI screen
bText - If TRUE, output will be written to a PrintStream (System.out by default)

setWriter

public void setWriter(java.io.PrintStream aStream)
Set the output stream.

Parameters:
aStream - A PrintStream to be used for output.

getWriter

public java.io.PrintStream getWriter()
Get the output stream (defaults to System.out).

Returns:
A PrintStream for output

addError

public void addError(Test test,
                     java.lang.Throwable t)
TestListener.addError() - will print 'E' to System.out.

Specified by:
addError in interface TestListener
Parameters:
test - The test that failed
t - The Exception that caused the error

addFailure

public void addFailure(Test test,
                       AssertionFailedError e)
TestListener.addError() - will print 'F' to System.out.

Specified by:
addFailure in interface TestListener
Parameters:
test - The test that failed
e - The AssertionFailedError that caused the failure

addToResultsList

public void addToResultsList(java.lang.String sText)
Add a string to the result output.

Parameters:
sText - The text to add

addToResultsList

public void addToResultsList(java.lang.Throwable t)
Add a string to the result output.

Parameters:
t - The text to add

endTest

public void endTest(Test test)
TestListener.endTest()

Specified by:
endTest in interface TestListener
Parameters:
test - The test that finished

endTestStep

public void endTestStep(Test test)
TestListener.endTestStep()

Specified by:
endTestStep in interface TestListener
Parameters:
test - The test of which a step has finished

print

public void print(TestResult result)
Prints errors and failures to the standard output

Parameters:
result - The test results

printErrors

public void printErrors(TestResult result)
Prints the errors to the standard output

Parameters:
result - The test result containing the errors

printFailures

public void printFailures(TestResult result)
Prints failures to the standard output

Parameters:
result - The test result containing the failures

printFooter

public void printFooter()
Prints the footer


printHeader

public void printHeader(TestResult result)
Prints the header of the report

Parameters:
result - DOCUMENT ME!

showResult

public void showResult()
To display the result of the test in a javax.microedition.lcdui.List screen.


startTest

public void startTest(Test test)
TestListener.startTest() - will print '.' to te System.out.

Specified by:
startTest in interface TestListener
Parameters:
test - The test that started

getResultsList

protected javax.microedition.lcdui.List getResultsList()
Returns the javax.microedition.lcdui.List instance to append the result data to. Will be created if it doesn't exist.

Returns:
A javax.microedition.lcdui.List object

createTestSuite

protected Test createTestSuite(java.lang.String[] rTestCaseClasses)
Builds a test suite from all test case classes in a string array.

Parameters:
rTestCaseClasses - A string array containing the test case class names
Returns:
A test suite containing all tests

destroyApp

protected void destroyApp(boolean bUnconditional)
Empty implementation of MIDlet.destroyApp.

Specified by:
destroyApp in class javax.microedition.midlet.MIDlet
Parameters:
bUnconditional - Not needed here

doRun

protected void doRun(Test suite)
Will run all tests in the given test suite.

Parameters:
suite - The test suite to run

pauseApp

protected void pauseApp()
Empty implementation of MIDlet.pauseApp.

Specified by:
pauseApp in class javax.microedition.midlet.MIDlet

start

protected void start(java.lang.String[] rTestCaseClasses)
Starts a test run. processes the command line arguments and creates a test suite from it. The test suite will then be run in a separate thread to allow the progress bar to be updated. After all tests have run the result screen will be displayed.

The only thing that a sub

Parameters:
rTestCaseClasses - The names of the test case classes

startApp

protected void startApp()
                 throws javax.microedition.midlet.MIDletStateChangeException
Default implementation that reads the attribute J2MEUnitTestClasses with getAppProperty and invokes the method start() with the result string. Therefore, if this string contains the space-separated list of test classes to run it is not necessary to subclass midletui.TestRunner.

Specified by:
startApp in class javax.microedition.midlet.MIDlet
javax.microedition.midlet.MIDletStateChangeException