|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ccl.util.Test
Framework and base class for all tests. Inherit _doit in your test and use bugIf( boolean ) statements for your actual test comparisons.
Features:
- support for stdout and stderr redirecting
Stdout redirection
Sometimes you test code which prints something to the console while for the test you don't want to confuse the user, since the test wants to print status information as well.
Console output will be redirected into two byte streams when desired (use 'Test.redirectStandardStreams( true )'). The test output will still be printed to the normal standard output streams.
When redirection takes place, the test can get a string with the last output to these streams and use this information for testing purposes as well. This buffer can also be cleaned anytime on purpose.
For an example how to write your own tests take a look at the ccl.util.test.UtilTest class.
If you write your own test code, extend from this test class and make sure you have these two constructors defined as they are expected from the Test base class in case you want to build a hierarchy of test classes.
public MyOwnTest() { super(); } public MyOwnTest( Test test ) { super( test ); }To execute your test code add for example the following code into your tests static main method:
public static void main( String[] args ) { Test test = new MyNewTest(); test.setVerbose( true ); test.setTiming ( true ); test.run(); test.printResult(); System.exit( 0 ); }So far you have not written any of your own test code and checks. These should go into the protected method '_doIt'. The test base class will invoke that method. Then you put all kinds of statements there which use the 'assert( boolean [, String] )' and 'bugIf( boolean [, String] )' methods of the base test class. Those assertions will be checked and counted. If any assertions fails the test class will print out a message as well as a stack trace. If the succeed a simple '.' will be printed. In the end the total time and the number of successful and total checks will be printed.
A successful run of the whole ccl test suite produces the following output:
Testing Main -> Testing Native . SUCCESS 00:00:00.023 -> Testing Util -> Testing text center formatting ...... SUCCESS 00:00:00.007 -> Testing text block formatting ........ SUCCESS 00:00:00.054 -> Testing OutputErrorStreamManager ............ SUCCESS 00:00:00.015 -> Testing SToLAndConcat ............................ SUCCESS 00:00:00.042 -> Testing FileUtil -> Testing copyDir ... SUCCESS 00:00:00.590 ........................................ SUCCESS 00:00:00.915 -> Testing Init ....................... SUCCESS 00:00:00.591 -> Testing IniFile .... SUCCESS 00:00:00.024 -> Testing ClassPathUtil .. SUCCESS 00:00:00.003 -> Testing SysEnv .... SUCCESS 00:00:00.026 -> Testing Singleton .. SUCCESS 00:00:00.004 ................ -> Testing atoi ................. SUCCESS 00:00:00.003 -> Testing Int/Bytes Conversion ..................................... SUCCESS 00:00:00.005 ................ -> Testing Date Validation .................. SUCCESS 00:00:00.016 ....... SUCCESS 00:00:01.877 -> Testing XMLUtil No Xalan XSLT parser found, skipping test! SUCCESS 00:00:00.008 -> Testing XMLImportHandler No PostgreSQL database found, skipping tests! SUCCESS 00:00:00.014 -> Testing SwingUtil ..... SUCCESS 00:00:10.969 SUCCESS 00:00:13.139 * * * * * * * * * * * * * * ccl.test.MainTest has finished. Hey, kewl, all 251 tests succeeded! :-)If you want to build a hierarchy of tests like in the example above, here is an example of how to do it. In your '_doIt' method you invoke another sub test like this:
protected void _doIt() throws Exception { Test testA = new ASubTest( this ); testA.run(); setTests( testA ); Test testB = new AnotherSubTest( this ); testB.run(); setTests( testB ); // do normal tests below // ... }In the output those two sub tests will then be indented and mentioned at least with their class name and the checks done inside will be added to the number of checks done in your current class.
UtilTest
Constructor Summary | |
Test()
Default constructor which should be overwritten by an implementation of a custom test class. |
|
Test(Test tstParent_)
If you build a hierarchy of test use this constructor to create a new sub test. |
Method Summary | |
protected abstract void |
_doIt()
Inherit this method to do your test inside of it. |
protected void |
_enterSubTest(java.lang.String sName_)
|
protected void |
_exitSubTest()
|
protected java.lang.Object |
_getValue()
|
protected void |
_increment()
|
protected void |
_setTests(Test pTest_)
Deprecated. Use setTests(..) instead. |
protected void |
_showLiveSignals(boolean bShowLiveSignals_)
Deprecated. Use setVerbose(..) instead. |
void |
assert(boolean bCheck_)
Deprecated. use 'Assert' instead since as of jdk release 1.4 'assert' is a keyword. |
void |
Assert(boolean bCheck_)
Conducts a check that a given object fullfills a given condition. |
void |
assert(boolean bCheck_,
java.lang.String sMessage_)
Deprecated. use 'Assert' instead since as of jdk release 1.4 'assert' is a keyword. |
void |
Assert(boolean bCheck_,
java.lang.String sMessage_)
Conducts a check that a given object fullfills a given condition. |
void |
assertEquals(boolean expected,
boolean actual)
Conducts a check that a given boolean equals another expected boolean value. |
void |
assertEquals(double actual,
double expected,
double delta)
Conducts a check that a given double valud equals another expected double value inside or equal to a given delta value. |
void |
assertEquals(double actual,
double expected,
double delta,
java.lang.String message)
Conducts a check that a given double valud equals another expected double value inside or equal to a given delta value. |
void |
assertEquals(java.lang.String message,
boolean expected,
boolean actual)
Conducts a check that a given boolean equals another expected boolean value. |
void |
assertEquals(java.lang.String message,
int expected,
int actual)
Conducts a check that a given integer equals another expected integer value. |
void |
assertEquals(java.lang.String expected,
java.lang.String actual)
Conducts a check that a given string equals another expected string value. |
void |
assertEquals(java.lang.String message,
java.lang.String expected,
java.lang.String actual)
Conducts a check that a given string equals another expected string value. |
void |
assertNotNull(java.lang.Object object_)
Conduct a check that a given object is not null. |
void |
assertNotNull(java.lang.Object object_,
java.lang.String sMessage_)
Conduct a check that a given object is not null. |
void |
assertTrue(boolean bCheck_)
Conducts a check that a given object fullfills a given condition. |
void |
assertTrue(boolean bCheck_,
java.lang.String sMessage_)
Conducts a check that a given object fullfills a given condition. |
void |
assertTrue(java.lang.String sMessage_,
boolean bCheck_)
Conducts a check that a given object fullfills a given condition. |
void |
bug(java.lang.String message)
Increases the test counter as well as the bug counter by one and prints the given message. |
boolean |
bugIf(boolean bCondition)
The opposite of assert. |
boolean |
bugIf(boolean bCondition,
java.lang.String sDescription)
The opposite of assert. |
boolean |
bugIf(boolean bCondition,
java.lang.String sDescription,
java.lang.Throwable pThrowable)
The opposite of assert. |
void |
fail()
Increases the test counter as well as the bug counter by one. |
void |
fail(java.lang.String message)
Increases the test counter as well as the bug counter by one and prints the given message. |
long |
getBugs()
The total number of failures found so far. |
java.lang.String |
getComment()
Return a one line comment for this test. |
long |
getGlobalTests()
The total number of tests done so far. |
long |
getLocalTests()
|
java.lang.String |
getName()
The application name of this test object. |
java.lang.String |
getTestClassDirectory()
Deprecated. Use getTestDirectory instead as this method will not work well together with jar files. |
java.lang.String |
getTestDirectory()
This method returns the full path of a dedicated test directory under the application directory. |
static java.lang.String |
getTestName(java.lang.Object testObject)
Given a test object it returns a string containing a name representing that test. |
static java.lang.String |
getTestName(java.lang.String sTestName)
Given a test object it returns a string containing a name representing that test. |
static java.lang.Object |
getValue()
|
void |
initialize(java.lang.String[] asArg_)
Process the arguments from the main class here. |
static boolean |
isTest()
|
boolean |
isTiming()
True if timing information gets printed in addition to the standard test output. |
boolean |
isVerbose()
Checks if each test condition handled will be visually presented with a dot on the standard output. |
void |
printResult()
Prints a summary of all tests to standard output. |
static void |
printResult(Test pTest_)
Prints a summary of all tests to standard output. |
static void |
redirectStandardStreams(boolean bRedirect_)
Redirect stdout and stderr into private streams so the do not confuse the user with test output. |
void |
run()
|
void |
setBug()
Count one more failure. |
void |
setParentTest(Test tstParent_)
If you build a hierarchy of test use this method to set a parent test object before running the checks of the sub test. |
void |
setTests(Test test_)
|
void |
setTiming(boolean bTiming_)
You want timing information? Set this to true! |
void |
setValue(java.lang.Object oValue_)
Deprecated. |
void |
setVerbose(boolean bVerbose_)
Defines if each test condition handled will be visually presented with a dot on the standard output. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Test()
public Test(Test tstParent_)
Method Detail |
protected java.lang.Object _getValue()
protected void _enterSubTest(java.lang.String sName_)
sName_
- e.g. "jacob".protected void _exitSubTest()
protected void _setTests(Test pTest_)
protected void _increment()
protected void _showLiveSignals(boolean bShowLiveSignals_)
public long getLocalTests()
public long getGlobalTests()
public long getBugs()
public void setBug()
public void setValue(java.lang.Object oValue_)
public boolean isVerbose()
public void setVerbose(boolean bVerbose_)
public void setTiming(boolean bTiming_)
public boolean isTiming()
public void printResult()
public static void printResult(Test pTest_)
public void setParentTest(Test tstParent_)
public boolean bugIf(boolean bCondition)
public boolean bugIf(boolean bCondition, java.lang.String sDescription)
public boolean bugIf(boolean bCondition, java.lang.String sDescription, java.lang.Throwable pThrowable)
public void assertNotNull(java.lang.Object object_)
public void assertNotNull(java.lang.Object object_, java.lang.String sMessage_)
sMessage_
- The message gets printed when the
assertion fails.public void assert(boolean bCheck_)
public void assert(boolean bCheck_, java.lang.String sMessage_)
sMessage_
- The message gets printed when the
assertion fails.public void Assert(boolean bCheck_)
public void Assert(boolean bCheck_, java.lang.String sMessage_)
sMessage_
- The message gets printed when the
assertion fails.public void assertTrue(boolean bCheck_)
public void assertTrue(boolean bCheck_, java.lang.String sMessage_)
sMessage_
- The message gets printed when the
assertion fails.public void assertTrue(java.lang.String sMessage_, boolean bCheck_)
sMessage_
- The message gets printed when the
assertion fails.public void assertEquals(java.lang.String message, boolean expected, boolean actual)
public void assertEquals(boolean expected, boolean actual)
public void assertEquals(java.lang.String message, int expected, int actual)
public void assertEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
public void assertEquals(java.lang.String expected, java.lang.String actual)
public void assertEquals(double actual, double expected, double delta)
This message does not conform to the JUnit API as it has the order of the expected and actual value object just the other way around, thought that should not make a difference.
public void assertEquals(double actual, double expected, double delta, java.lang.String message)
This message does not conform to the JUnit API as the message string is the last parameter and not the first.
public void fail(java.lang.String message)
bug(java.lang.String)
public void fail()
bug(java.lang.String)
public void bug(java.lang.String message)
fail(java.lang.String)
protected abstract void _doIt() throws java.lang.Exception
java.lang.Exception
- Whatever can go wrong.public void run()
run
in interface java.lang.Runnable
public java.lang.String getName()
public static java.lang.String getTestName(java.lang.Object testObject)
public static java.lang.String getTestName(java.lang.String sTestName)
sTestName
- name of a test class, e.g. "UtilTest".public void initialize(java.lang.String[] asArg_)
public static boolean isTest()
public static java.lang.Object getValue()
public java.lang.String getTestClassDirectory()
getTestDirectory()
public java.lang.String getTestDirectory()
public java.lang.String toString()
toString
in class java.lang.Object
public void setTests(Test test_)
public java.lang.String getComment()
public static void redirectStandardStreams(boolean bRedirect_)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |