lejosunit.rcxui
Class TestRunner

java.lang.Object
  extended bylejosunit.rcxui.TestRunner
All Implemented Interfaces:
josx.platform.rcx.ButtonListener, TestListener
Direct Known Subclasses:
TestRunnerTest.MyTestRunner

public class TestRunner
extends java.lang.Object
implements TestListener, josx.platform.rcx.ButtonListener

A TestRunner based on the RCX implementation of leJOS. This TestRunner has to be started through a main program of the test cases. Example:

 public class MyTest {
   public static void main(String[] args) {
     lejosunit.rcxui.TestRunner.main(suite());
   }
   public static Test suite() {
     TestSuite suite = new TestSuite();
     suite.addTest(new OneTest ("testOne"));
     suite.addTest(new OneTest ("testTwo"));
     return suite;
   }
 }
 
The TestRunner has a small user interface:

Author:
Jochen Hiller

Field Summary
static byte DISPLAY_MODE_EMULATOR
          display mode when running in emulator
static byte DISPLAY_MODE_RCX
          display mode when running at rcx
static byte DISPLAY_MODE_SILENT
          display mode when running in silent mode for tests
 
Constructor Summary
TestRunner()
           
 
Method Summary
 void addError(Test test, java.lang.Throwable t)
          Add an error to the runner.
 void addFailure(Test test, AssertionFailedError t)
          Add a failure to the runner.
 void buttonPressed(josx.platform.rcx.Button button)
          The buttonPressed will define the UI behaviour.
 void buttonReleased(josx.platform.rcx.Button button)
          The buttonRelease will completely be ignored.
protected  TestResult createTestResult()
          Creates the TestResult to be used for the test run.
 TestResult doRun(Test suite)
          Run a test or test suite.
 TestResult doRun(Test suite, byte mode)
          Run a test or test suite.
 void endTest(Test test)
          Ends a test.
 java.lang.String getDisplayBuffer()
          Get the actual display buffer.
 char[] getDisplayBufferShown()
          Get the actual display buffer shown in display.
static void main(Test suite)
          Main program to start the test runner.
static void main(Test suite, boolean doWait)
          Main program to start the test runner.
protected  void refreshDisplayBuffer()
          Refresh the display buffer on TextLCD
protected  void runUntilStopped()
          Will run the TestRunner forever.
protected  void scrollLeft()
          Scrolls one character to left.
protected  void scrollRight()
          Scrolls one character to right.
 void startTest(Test test)
          Starts a test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISPLAY_MODE_SILENT

public static final byte DISPLAY_MODE_SILENT
display mode when running in silent mode for tests

See Also:
Constant Field Values

DISPLAY_MODE_RCX

public static final byte DISPLAY_MODE_RCX
display mode when running at rcx

See Also:
Constant Field Values

DISPLAY_MODE_EMULATOR

public static final byte DISPLAY_MODE_EMULATOR
display mode when running in emulator

See Also:
Constant Field Values
Constructor Detail

TestRunner

public TestRunner()
Method Detail

main

public static void main(Test suite)
                 throws java.lang.RuntimeException
Main program to start the test runner. Will exit the program after completion.

Parameters:
suite - the test or test suite to run
Throws:
java.lang.RuntimeException - will be raised through an internal error at TestRunner

main

public static void main(Test suite,
                        boolean doWait)
                 throws java.lang.RuntimeException
Main program to start the test runner. If doWait, it will be run forever. The display can be scrolled, the tests can be restarted.

Parameters:
suite - the test or test suite to run
doWait - if true, the TestRunner will go into a infinite loop, to enable scrolling, re-run etc.
Throws:
java.lang.RuntimeException - will be raised through an internal error at TestRunner

buttonPressed

public void buttonPressed(josx.platform.rcx.Button button)
The buttonPressed will define the UI behaviour. When pressing the buttob RUN, the running test suite will be stopped.

Specified by:
buttonPressed in interface josx.platform.rcx.ButtonListener
Parameters:
button - a button from the RCX

buttonReleased

public void buttonReleased(josx.platform.rcx.Button button)
The buttonRelease will completely be ignored.

Specified by:
buttonReleased in interface josx.platform.rcx.ButtonListener
Parameters:
button - a button from the RCX

doRun

public TestResult doRun(Test suite)
Run a test or test suite.

Parameters:
suite - the tests to run
Returns:
the test result of the run

doRun

public TestResult doRun(Test suite,
                        byte mode)
Run a test or test suite.

Parameters:
suite - the tests to run
mode - the display mode. Either DISPLAY_MODE_SILENT, DISPLAY_MODE_RCX, DISPLAY_MODE_EMULATOR
Returns:
the test result of the run

startTest

public void startTest(Test test)
Starts a test. Will display an "." to indicate a started test.

Specified by:
startTest in interface TestListener
Parameters:
test - the raising test

endTest

public void endTest(Test test)
Ends a test. Will do nothing.

Specified by:
endTest in interface TestListener
Parameters:
test - the raising test

addError

public void addError(Test test,
                     java.lang.Throwable t)
Add an error to the runner. Will display an "E" to indicate an error.

Specified by:
addError in interface TestListener
Parameters:
test - the raising test
t - the throwable raising the error

addFailure

public void addFailure(Test test,
                       AssertionFailedError t)
Add a failure to the runner. Will display an "F" to indicate an assertion failure.

Specified by:
addFailure in interface TestListener
Parameters:
test - the raising test
t - the assertion failed error

refreshDisplayBuffer

protected void refreshDisplayBuffer()
Refresh the display buffer on TextLCD


getDisplayBuffer

public java.lang.String getDisplayBuffer()
Get the actual display buffer. Necessary to make this class applicable for tests.

Returns:
the buffer for the display

getDisplayBufferShown

public char[] getDisplayBufferShown()
Get the actual display buffer shown in display.

Returns:
the buffer for the display

runUntilStopped

protected void runUntilStopped()
                        throws java.lang.InterruptedException
Will run the TestRunner forever.

Throws:
java.lang.InterruptedException - can be raised from Thread.sleep

createTestResult

protected TestResult createTestResult()
Creates the TestResult to be used for the test run.

Returns:
the created test result

scrollLeft

protected void scrollLeft()
Scrolls one character to left.


scrollRight

protected void scrollRight()
Scrolls one character to right.



Copyright (C) 2003 Jochen Hiller. All Rights Reserved.