📄 testharness.java
字号:
}
}
// execute the test suite and print the results
TestResult results = harness.execute(suite);
harness.getTestRunner().print(results);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
provider.cleanup(true);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
} else {
usage();
}
}
/**
* The default constructor is used to instantiate an instance
* of this class
*/
TestHarness() {
}
// implementation of TestListener.startTest
public void startTest(Test test) {
if (test instanceof TestCase) {
System.err.print("\nexecuting " + test.getClass().getName() + "."
+ ((TestCase)test).getName());
} else if (test instanceof TestSuite) {
System.err.print("\nin test suite " + ((TestSuite)test).getName());
}
}
// implementation of TestListenr.addError
public void addError(Test test, Throwable throwable) {
System.err.print("...[error]");
}
// implementation of TestListener.addFailure
public void addFailure(Test test, AssertionFailedError throwable) {
System.err.print("...[failure]");
}
// implementation of TestListener.endTest
public void endTest(Test test) {
System.err.print("...[passed]");
}
/**
* Return the compiled test suite. Initially this will statically
* compiled although future releases will read a configuration file
* and dynamically compile the test suite.
*
* @param file - the configuration file
* @return TestSuite - the test suite
* @throws RuntimeException - if file does not exist or file is in error.
*/
TestSuite getTestSuite() {
if (_suite == null) {
_suite = new TestSuite("openjms");
_suite.addTest(new TestSuite(TestConfigurationComponent.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug696.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug669.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug719.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug726.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug781.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug888.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug889.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug894.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug966.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug665495.class));
_suite.addTest(new TestSuite(org.exolab.testharness.jms.bugs.TestBug705640.class));
}
return _suite;
}
/**
* Execute all the tests in the specified test suite. This method will
* create and return a TestResult object, which maintains the state of
* all tests executed.
*
* @param suite - the test suite to execute
* @return TestResult - the result set
*/
TestResult execute(TestSuite suite) {
TestResult result = new TestResult();
result.addListener(this);
// execute the test cases and return the result set to
// the calling application
suite.run(result);
return result;
}
/**
* This is a recursive function that selects all tests matching
* the specified expression and places them in the supplied results.
* <p>
* The results parameter cannot be non-null otherwise an
* {@link IllegalArgumentException} exception is thrown. Similar
* for expression and suite.
*
* @param suite - the test suite to inspect
* @param results - matching test cases are stored here.
* @param expression - a regular expresion
*/
void getMatchingTests(TestSuite suite, TestSuite results,
Pattern expression) {
if ((suite == null) || (results == null) || expression == null) {
throw new IllegalArgumentException(
"getMatchingTests : cannot have null input param");
}
Perl5Matcher matcher = new Perl5Matcher();
Enumeration tests = suite.tests();
while (tests.hasMoreElements()) {
// for every test case. If the expression matches the
// name of the test case it is added to the result
// set.
Test test = (Test)tests.nextElement();
if (test instanceof TestCase) {
String name = test.getClass().getName() + "." +
((TestCase)test).getName();
if (matcher.matches(name, expression)) {
results.addTest(test);
}
} else if (test instanceof TestSuite) {
// make a recursice call
getMatchingTests((TestSuite)test, results, expression);
}
}
}
/**
* Display the list of test cases registered with the specified
* test suite on to the console
*
* @param suite - the test suite
*/
void displayTests(TestSuite suite) {
Enumeration tests = suite.tests();
while (tests.hasMoreElements()) {
Test test = (Test)tests.nextElement();
if (test instanceof TestCase) {
System.err.println(++_index + ". " + test.getClass().getName() +
"." + ((TestCase)test).getName());
} else if (test instanceof TestSuite) {
displayTests((TestSuite)test);
} else {
System.err.println(++_index + ". " + test.getClass().getName());
}
}
}
/**
* Retrieve an instance of the {@link TestRunner}. If one does not exist
* then create it
*
* @return TestRunner
*/
TestRunner getTestRunner() {
if (_runner == null) {
_runner = new TestRunner();
}
return _runner;
}
/**
* Displays usage information on the console
*/
public static void usage() {
PrintStream out = System.out;
out.println("Usage: java [jvm options] " + TestHarness.class + " [args...]");
out.println("\nwhere args are:");
out.println(" -execute <regex> execute the test cases. If a regular expression");
out.println(" is not specified all test cases are executed.");
out.println(" If regular expression specified only matching");
out.println(" test cases are executed.");
out.println(" -config <file> openjms server configuration file to use for test");
out.println(" -display display a list of registered test case.");
out.println(" -help display this help screen");
out.println("");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -