ccl.util
Class Test

java.lang.Object
  |
  +--ccl.util.Test
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ClassPathUtilTest, DateFieldTest, DoubleListTest, FileUtilTest, IniFileTest, InitTest, InputCancelDialogTest, MainTest, NativeTest, OutputErrorStreamManagerTest, SingletonTest, SToLAndConcatTest, SwingUtilTest, SysEnvTest, TestTest, TestTest.FailingTest, TestTest.SuccessfullTest, UtilTest, XMLImportHandlerTest, XMLUtilTest

public abstract class Test
extends java.lang.Object
implements java.lang.Runnable

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

See Also:
UtilTest

Constructor Summary
Test()
           
Test(Test tstParent_)
           
 
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_)
          Conduct a check that a given object fullfills a given condition.
 void assert(boolean bCheck_, java.lang.String sMessage_)
          Conduct a check that a given object fullfills a given condition.
 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.
 boolean bugIf(boolean bCondition)
           
 boolean bugIf(boolean bCondition, java.lang.String sDescription)
           
 boolean bugIf(boolean bCondition, java.lang.String sDescription, java.lang.Throwable pThrowable)
           
 long getBugs()
           
 java.lang.String getComment()
          Return a one line comment for this test.
 long getGlobalTests()
           
 long getLocalTests()
           
 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.Object getValue()
           
 void initialize(java.lang.String[] asArg_)
          Process the arguments from the main class here.
static boolean isTest()
           
 boolean isTiming()
           
 boolean isVerbose()
           
static void main(java.lang.String[] argv)
          example code for a real test main method
static void printResult(Test pTest_)
           
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()
           
 void setTests(Test test_)
           
 void setTiming(boolean bTiming_)
          You want timing information? Set this to true!
 void setValue(java.lang.Object oValue_)
           
 void setVerbose(boolean bVerbose_)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Test

public Test()

Test

public Test(Test tstParent_)
Method Detail

_getValue

protected java.lang.Object _getValue()

_enterSubTest

protected void _enterSubTest(java.lang.String sName_)
Parameters:
sName_ - e.g. "jacob".

_exitSubTest

protected void _exitSubTest()

_setTests

protected void _setTests(Test pTest_)
Deprecated. Use setTests(..) instead.


_increment

protected void _increment()

_showLiveSignals

protected void _showLiveSignals(boolean bShowLiveSignals_)
Deprecated. Use setVerbose(..) instead.


getLocalTests

public long getLocalTests()

getGlobalTests

public long getGlobalTests()

getBugs

public long getBugs()

setBug

public void setBug()

setValue

public void setValue(java.lang.Object oValue_)

isVerbose

public boolean isVerbose()

setVerbose

public void setVerbose(boolean bVerbose_)

setTiming

public void setTiming(boolean bTiming_)
You want timing information? Set this to true!

isTiming

public boolean isTiming()

printResult

public static void printResult(Test pTest_)

bugIf

public boolean bugIf(boolean bCondition)

bugIf

public boolean bugIf(boolean bCondition,
                     java.lang.String sDescription)

bugIf

public boolean bugIf(boolean bCondition,
                     java.lang.String sDescription,
                     java.lang.Throwable pThrowable)

assertNotNull

public void assertNotNull(java.lang.Object object_)
Conduct a check that a given object is not null. Otherwise count as a failed test.

assertNotNull

public void assertNotNull(java.lang.Object object_,
                          java.lang.String sMessage_)
Conduct a check that a given object is not null. Otherwise count as a failed test.
Parameters:
sMessage_ - The message gets printed when the assertion fails.

assert

public void assert(boolean bCheck_)
Conduct a check that a given object fullfills a given condition. If this condition is not fullfilled (boolean is false) count this check as a failed test.

assert

public void assert(boolean bCheck_,
                   java.lang.String sMessage_)
Conduct a check that a given object fullfills a given condition. If this condition is not fullfilled (boolean is false) count this check as a failed test.
Parameters:
sMessage_ - The message gets printed when the assertion fails.

_doIt

protected abstract void _doIt()
                       throws java.lang.Exception
Inherit this method to do your test inside of it.
Throws:
java.lang.Exception - Whatever can go wrong.

run

public void run()
Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] argv)
example code for a real test main method

 Test pTest = (Test)(new SomeTest());
 pTest.initialize( argv );
 pTest.setVerbose( true );
 pTest.run();
 printResult( pTest );

 System.exit( 0 );
 

initialize

public void initialize(java.lang.String[] asArg_)
Process the arguments from the main class here. This way you can pass arguments to this test also from the test center, which does not use the main method to invoke a test.

isTest

public static boolean isTest()

getValue

public static java.lang.Object getValue()

getTestClassDirectory

public java.lang.String getTestClassDirectory()
Deprecated. Use getTestDirectory instead as this method will not work well together with jar files.

Returns the directory of the class on which this method is invoked.
See Also:
getTestDirectory()

getTestDirectory

public java.lang.String getTestDirectory()
This method returns the full path of a dedicated test directory under the application directory.
Returns:
a string for a director with test data for the current application, e.g. "/home/clemens/src/java/jacob/test".

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setTests

public void setTests(Test test_)

getComment

public java.lang.String getComment()
Return a one line comment for this test. Should be overwritten be test classes inheriting from this class.

redirectStandardStreams

public static void redirectStandardStreams(boolean bRedirect_)
Redirect stdout and stderr into private streams so the do not confuse the user with test output. Look at the class documentation at the top for detailed stdout redirection documentation.