/** *RBTestFmwkisabaseclassforteststhatcanberunconvenientlyfrom *thecommandlineaswellasundertheJavatestharness. *<p> *Sub-classesimplementasetofmethodsnamedTest<something>.Each *ofthesemethodsperformssometest.Testmethodsshouldindicate *errorsbycallingeithererrorerrln.Thiswillincrementthe *errorCountfieldandmayoptionallyprintamessagetothelog. *Debugginginformationmayalsobeaddedtothelogviathelog *andloglnmethods.Thesemethodswilladdtheirargumentstothe *logonlyifthetestisbeingruninverbosemode.
*/ publicclass RBTestFmwk { //------------------------------------------------------------------------ // Everything below here is boilerplate code that makes it possible // to add a new test by simply adding a function to an existing class //------------------------------------------------------------------------
protected RBTestFmwk() { // Create a hashtable containing all the test methods.
testMethods = new Hashtable();
Method[] methods = getClass().getDeclaredMethods(); for( int i=0; i<methods.length; i++ ) { if( methods[i].getName().startsWith("Test")
|| methods[i].getName().startsWith("test") ) {
testMethods.put( methods[i].getName(), methods[i] );
}
}
}
// Set up the log and reference streams. We use PrintWriters in order to // take advantage of character conversion. The JavaEsc converter will // convert Unicode outside the ASCII range to Java's \\uxxxx notation.
log = new PrintWriter(System.out,true);
// Parse the test arguments. They can be either the flag // "-verbose" or names of test methods. Create a list of // tests to be run.
Vector testsToRun = new Vector( args.length ); for( int i=0; i<args.length; i++ ) { if( args[i].equals("-verbose") ) {
verbose = true;
} elseif( args[i].equals("-prompt") ) {
prompt = true;
} elseif (args[i].equals("-nothrow")) {
nothrow = true;
} else {
Object m = testMethods.get( args[i] ); if( m != null ) {
testsToRun.addElement( m );
} else {
usage(); return;
}
}
}
// If no test method names were given explicitly, run them all. if( testsToRun.size() == 0 ) {
Enumeration methodNames = testMethods.elements(); while( methodNames.hasMoreElements() ) {
testsToRun.addElement( methodNames.nextElement() );
}
}
// Run the list of tests given in the test arguments for( int i=0; i<testsToRun.size(); i++ ) { int oldCount = errorCount;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.