📄 testharness.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: TestHarness.java,v 1.10 2003/03/27 10:28:02 jalateras Exp $
*
* Date Author Changes
* 07/30/2001 jima Created
*/
package org.exolab.testharness.jms;
// java util
import java.util.Enumeration;
// java.io
import java.io.PrintStream;
// junit framework
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestListener;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.framework.AssertionFailedError;
import junit.textui.TestRunner;
// utility classes
import org.exolab.jms.util.CommandLine;
// regular expression library
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
// openjms library
import org.exolab.testharness.jms.config.TestConfigurationComponent;
import org.exolab.testharness.jms.util.OpenJMSProvider;
/**
* The test harness extends the JUnit framework to support extended
* facilities, such as running a portion of the test harness or displating
* all the test cases in the test harness. It also uses an extension to
* TestResult, which captures the results as an XML document, which can
* then be translated to a different format through XSLT.
* <p>
* The test harness is dynamically constructed by reading a configuration
* files that list the class names of all test suites and test cases. A
* test suite is build from a class that extends TestCase. It simply looks
* for all method that are public and begin with 'test'. A TestCase is a
* single instance that implements the 'run' methood.
* <p>
* The TestHarness is composed of two parts, tests related to the various
* components of OpenJMS and tests related to bug reports.
* <p>
* Tests relevant to a particular component will be grouped together into a
* test suite. The test cases that relate to bug reports will also be grouped
* together. The class names of these test cases will be in the form TestBugXXX
* where XXX is the bug report number.
* <p>
* The schema for the input configuration file is shown below
* <testHarness>
* <testSuite name="bugs">
* <testCase class="fully qualified name of class" method="methodName" />
* <testCase class="fully qualified name of class" />
* <testSuite
* </testSuite>
* </testHarness>
*/
final public class TestHarness
implements TestListener {
/**
* Used to count the number of test cases
*/
private static int _index = 0;
/**
* Caches an instance of a test runner that is used by this application
*/
private TestRunner _runner = null;
/**
* Holds the test suite, which maintains a list of test cases to execute
*/
private TestSuite _suite = null;
/**
* The default name name of the log4j properties file
*/
private static String _logPropertyFile = "log4j.xml";
/**
* The following options are supported by this application
* <p>
* -file
* the file that containing the test cases to exec.
* -display
* display all the test cases
* -execute <expression>
* if expression is missing it will execute all the tests in the
* test suite, otherwise it will only execute matching test cases.
*/
public static void main(String[] args) {
// process the command line
CommandLine line = new CommandLine(args);
if (line.exists("help")) {
usage();
} else if (line.exists("display") ||
(line.exists("execute") && line.exists("config"))) {
// the correct combination of commnad lines were specified so
// we can go ahead and process it.
TestHarness harness = new TestHarness();
if (line.exists("display")) {
_index = 0;
harness.displayTests(harness.getTestSuite());
}
if (line.exists("execute")) {
String path = line.value("config");
if (path == null) {
throw new RuntimeException(
"No configuration file was specified");
}
OpenJMSProvider provider = new OpenJMSProvider();
provider.setPath(path);
try {
// we need to start the provider before we execute
// any of the tests
provider.initialise(true);
// now determine whether execute was specified as a switch
// or a command line option. If it was a switch then we need
// to execute the complete test suite. If it was a parameter
// then we treat the value as a regular expression, find
// all matching test cases and execute them
TestSuite suite = null;
if (line.isSwitch("execute")) {
suite = harness.getTestSuite();
} else {
try {
Perl5Compiler compiler = new Perl5Compiler();
Pattern expression = compiler.compile(
line.value("execute"));
TestSuite matching = new TestSuite();
harness.getMatchingTests(harness.getTestSuite(),
matching, expression);
// assign them
suite = matching;
} catch (MalformedPatternException exception) {
throw new RuntimeException(
"Bad regular expression: " +
exception.toString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -