All Packages Class Hierarchy This Package Previous Next Index
Class cryptix.util.test.BaseTest
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----cryptix.util.test.BaseTest
- public abstract class BaseTest
- extends Applet
This abstract class acts as a base for all Cryptix test classes.
Its purpose is to provide a framework that will allow us to easily add new
testing features. Features that have already been added include:
- only printing complete output when one or more tests fail.
Planned features include:
- testing as an applet,
- testing as a standalone GUI program (with the -gui option),
- repeating tests that have failed at a higher debugging level.
Copyright © 1997, 1998
Systemics Ltd on behalf of the
Cryptix Development Team.
All rights reserved.
$Revision: 1.5 $
- Author:
- David Hopwood
-
out
- The PrintWriter to which delayed output is sent.
-
status
- The PrintWriter to which immediate output is sent.
-
BaseTest()
- Constructor for use by subclasses.
-
commandline(String[])
- Used to run a test from the command line.
-
commandline(String[], int)
- Used to run a test from the command line, skipping the first offset
arguments (which are assumed to have been processed by the subclass).
-
describeOptions()
- Describes the command-line options of this class.
-
describeUsage()
- Describes the command-line usage of this class.
-
engineTest()
- This method should be overridden by test subclasses, to perform the
actual testing.
-
error(Exception)
- Reports an error due to an unexpected exception.
-
error(String)
- Reports an error, with the given message.
-
error(Throwable)
-
-
fail(String)
- Reports a failure, with the given message.
-
getErrors()
- Returns the number of errors so far.
-
getExpectedPasses()
- Returns the number of expected passes, or 0 if this has not yet been
set, or is unknown.
-
getFailures()
- Returns the number of failures so far.
-
getName()
- Gets the name of this test (as shown to the user).
-
getPasses()
- Returns the number of passes so far.
-
getSkipped()
- Returns the number of skipped tests so far.
-
init()
- Used when the test is running as an Applet.
-
isGuiEnabled()
- Returns true iff a GUI interface is being used.
-
isOverallPass()
- Returns true iff all the tests have completed successfully.
-
isVerbose()
- Returns true iff output is to be printed even if all tests pass.
-
parseOption(String)
- Parses a command-line option.
-
parseOptions(String[], int)
- Processes command-line arguments from args, starting at index
offset.
-
pass(String)
- Reports a pass, with the given message.
-
passIf(boolean, String)
- Reports a pass if pass is true, or a failure if it is false.
-
report()
- Forces a report of the number of passes, failures, errors, and expected
passes so far.
-
setExpectedPasses(int)
- Sets the number of expected passes for this test class.
-
setGuiEnabled(boolean)
- Sets whether a GUI interface is used.
-
setName(String)
- Sets the name of this test (as shown to the user).
-
setOutput(PrintWriter)
- Sets the PrintWriter to which output is to be sent.
-
setVerbose(boolean)
- Sets whether output is to be printed even if all tests pass.
-
skip(String)
- Reports a skipped test, with the given message.
-
test()
- Begins the test proper.
-
waitForExit()
- Blocks until it is time to exit.
status
protected PrintWriter status
- The PrintWriter to which immediate output is sent.
out
protected PrintWriter out
- The PrintWriter to which delayed output is sent.
BaseTest
protected BaseTest()
- Constructor for use by subclasses.
init
public synchronized void init()
- Used when the test is running as an Applet.
- Overrides:
- init in class Applet
setGuiEnabled
public synchronized void setGuiEnabled(boolean flag)
- Sets whether a GUI interface is used.
isGuiEnabled
public boolean isGuiEnabled()
- Returns true iff a GUI interface is being used.
waitForExit
public synchronized void waitForExit()
- Blocks until it is time to exit.
commandline
protected void commandline(String args[])
- Used to run a test from the command line. Each test class' main method
should create an instance and call the
commandline
method on it, passing the array of command line arguments. For example,
in class TestFoo:
public static void main(String[] args) {
new TestFoo().commandline(args);
}
commandline
protected void commandline(String args[],
int offset)
- Used to run a test from the command line, skipping the first offset
arguments (which are assumed to have been processed by the subclass).
parseOption
protected void parseOption(String option) throws TestException
- Parses a command-line option. If the option is not recognised,
super.parseOption(option)
should be called.
Case should generally not be significant in option names.
parseOptions
public void parseOptions(String args[],
int offset) throws TestException
- Processes command-line arguments from args, starting at index
offset.
describeUsage
public String describeUsage()
- Describes the command-line usage of this class.
describeOptions
public String describeOptions()
- Describes the command-line options of this class.
setName
public void setName(String n)
- Sets the name of this test (as shown to the user). The default is the name of
the class.
- Overrides:
- setName in class Component
getName
public String getName()
- Gets the name of this test (as shown to the user).
- Overrides:
- getName in class Component
setOutput
public void setOutput(PrintWriter pw)
- Sets the PrintWriter to which output is to be sent. In most cases this
does not need to be set by the test class; the
commandline
method will do that automatically.
setVerbose
public void setVerbose(boolean flag)
- Sets whether output is to be printed even if all tests pass.
isVerbose
public boolean isVerbose()
- Returns true iff output is to be printed even if all tests pass.
test
public void test() throws TestException
- Begins the test proper. This method is called automatically by
commandline
, but it can also be called directly.
fail
protected void fail(String msg)
- Reports a failure, with the given message.
error
protected void error(String msg)
- Reports an error, with the given message.
skip
protected void skip(String msg)
- Reports a skipped test, with the given message.
error
protected void error(Exception e)
- Reports an error due to an unexpected exception.
error
protected void error(Throwable e)
pass
protected void pass(String msg)
- Reports a pass, with the given message.
passIf
protected void passIf(boolean pass,
String msg)
- Reports a pass if pass is true, or a failure if it is false.
In either case, the given message is used.
setExpectedPasses
protected void setExpectedPasses(int n)
- Sets the number of expected passes for this test class. This can be
called at any time by the
engineTest
method, but should
normally be called at the start of that method.
report
protected void report()
- Forces a report of the number of passes, failures, errors, and expected
passes so far.
getFailures
public int getFailures()
- Returns the number of failures so far.
getErrors
public int getErrors()
- Returns the number of errors so far.
getPasses
public int getPasses()
- Returns the number of passes so far.
getSkipped
public int getSkipped()
- Returns the number of skipped tests so far.
getExpectedPasses
public int getExpectedPasses()
- Returns the number of expected passes, or 0 if this has not yet been
set, or is unknown.
isOverallPass
public boolean isOverallPass()
- Returns true iff all the tests have completed successfully.
engineTest
protected abstract void engineTest() throws Exception
- This method should be overridden by test subclasses, to perform the
actual testing.
All Packages Class Hierarchy This Package Previous Next Index