String method= \"\";
boolean wait= false;
for (int i= 0; i < args.length; i++) ...{
if (args[i].equals(\"-wait\"))
wait= true;
else if (args[i].equals(\"-c\"))
testCase= extractClassName(args[++i]);
else if (args[i].equals(\"-m\")) ...{
String arg= args[++i];
int lastIndex= arg.lastIndexOf(’.’);
testCase= arg.substring(0, lastIndex);
method= arg.substring(lastIndex + 1);
} else if (args[i].equals(\"-v\"))
System.err.println(\"JUnit \" + Version.id() + \" by Kent Beck and Erich Gamma\");
else
testCase= args[i];
}
if (testCase.equals(\"\"))
throw new Exception(\"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class\");
try ...{
if (!method.equals(\"\"))
return runSingleMethod(testCase, method, wait);
Test suite= getTest(testCase);
return doRun(suite, wait); } catch (Exception e) ...{
throw new Exception(\"Could not create and run test suite: \" + e);
}
}
/** *//**
*运行某个test 方法
*/
public TestResult doRun(Test suite, boolean wait) ...{
TestResult result= createTestResult();
result.addListener(fPrinter);
long startTime= System.currentTimeMillis();
suite.run(result);
long endTime= System.currentTimeMillis();
long runTime= endTime-startTime;
fPrinter.print(result, runTime);
pause(wait);
return result;
}
/** *//**
* 主类入口
*/
public static void main(String args[]) ...{
TestRunner aTestRunner= new TestRunner();
try ...{
TestResult r= aTestRunner.start(args);
if (!r.wasSuccessful())
System.exit(FAILURE_EXIT);
System.exit(SUCCESS_EXIT);
} catch(Exception e) ...{
System.err.println(e.getMessage());
System.exit(EXCEPTION_EXIT);
}
}
}
--------------- 遇到的问题 ------------------
junit4可以使用@来定义测试方法,而以前的版本则是通过名字testXX来确定软件测试方法,
这就导致 testRunner不能识别@标记的方法....解决方法正在寻找中..
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/