标签:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package junit.textui;
import java.io.PrintStream;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.runner.BaseTestRunner;
import junit.runner.Version;
import junit.textui.ResultPrinter;
public class TestRunner extends BaseTestRunner {
private ResultPrinter fPrinter;
public static final int SUCCESS_EXIT = 0;
public static final int FAILURE_EXIT = 1;
public static final int EXCEPTION_EXIT = 2;
public TestRunner() {
this(System.out);
}
public TestRunner(PrintStream writer) {
this(new ResultPrinter(writer));
}
public TestRunner(ResultPrinter printer) {
this.fPrinter = printer;
}
public static void run(Class<? extends TestCase> testClass) {
run((Test)(new TestSuite(testClass)));
}
public static TestResult run(Test test) {
TestRunner runner = new TestRunner();
return runner.doRun(test);
}
public static void runAndWait(Test suite) {
TestRunner aTestRunner = new TestRunner();
aTestRunner.doRun(suite, true);
}
public void testFailed(int status, Test test, Throwable t) {
}
public void testStarted(String testName) {
}
public void testEnded(String testName) {
}
protected TestResult createTestResult() {
return new TestResult();
}
public TestResult doRun(Test test) {
return this.doRun(test, false);
}
public TestResult doRun(Test suite, boolean wait) {
TestResult result = this.createTestResult();
result.addListener(this.fPrinter);
long startTime = System.currentTimeMillis();
suite.run(result);
long endTime = System.currentTimeMillis();
long runTime = endTime - startTime;
this.fPrinter.print(result, runTime);
this.pause(wait);
return result;
}
protected void pause(boolean wait) {
if(wait) {
this.fPrinter.printWaitPrompt();
try {
System.in.read();
} catch (Exception var3) {
;
}
}
}
public static void main(String[] args) {
TestRunner aTestRunner = new TestRunner();
try {
TestResult e = aTestRunner.start(args);
if(!e.wasSuccessful()) {
System.exit(1);
}
System.exit(0);
} catch (Exception var3) {
System.err.println(var3.getMessage());
System.exit(2);
}
}
public TestResult start(String[] args) throws Exception {
String testCase = "";
String method = "";
boolean wait = false;
for(int e = 0; e < args.length; ++e) {
if(args[e].equals("-wait")) {
wait = true;
} else if(args[e].equals("-c")) {
++e;
testCase = this.extractClassName(args[e]);
} else if(args[e].equals("-m")) {
++e;
String arg = args[e];
int lastIndex = arg.lastIndexOf(46);
testCase = arg.substring(0, lastIndex);
method = arg.substring(lastIndex + 1);
} else if(args[e].equals("-v")) {
System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
} else {
testCase = args[e];
}
}
if(testCase.equals("")) {
throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
} else {
try {
if(!method.equals("")) {
return this.runSingleMethod(testCase, method, wait);
} else {
Test var9 = this.getTest(testCase);
return this.doRun(var9, wait);
}
} catch (Exception var8) {
throw new Exception("Could not create and run test suite: " + var8);
}
}
}
protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception {
Class testClass = this.loadSuiteClass(testCase).asSubclass(TestCase.class);
Test test = TestSuite.createTest(testClass, method);
return this.doRun(test, wait);
}
protected void runFailed(String message) {
System.err.println(message);
System.exit(1);
}
public void setPrinter(ResultPrinter printer) {
this.fPrinter = printer;
}
}
上面是 Junit 的入口程序
标签:
原文地址:http://www.cnblogs.com/wind90/p/5011144.html