testng的入口在哪裏
先上圖。
入口就在這個包裏邊.具體的類就是testNG.class
/**
* The TestNG entry point for command line execution.
*
* @param argv the TestNG command line parameters.
* @throws FileNotFoundException
*/
public static void main(String[] argv) {
TestNG testng = privateMain(argv, null);
System.exit(testng.getStatus());
}
/**
* <B>Note</B>: this method is not part of the public API and is meant for internal usage only.
*/
public static TestNG privateMain(String[] argv, ITestListener listener) {
TestNG result = new TestNG();
if (null != listener) {
result.addListener(listener);
}
//
// Parse the arguments
//
try {
CommandLineArgs cla = new CommandLineArgs();
m_jCommander = new JCommander(cla, argv);
validateCommandLineParameters(cla);
result.configure(cla);
}
catch(ParameterException ex) {
exitWithError(ex.getMessage());
}
//
// Run
//
try {
result.run();
}
catch(TestNGException ex) {
if (TestRunner.getVerbose() > 1) {
ex.printStackTrace(System.out);
}
else {
error(ex.getMessage());
}
result.setStatus(HAS_FAILURE);
}
return result;
}
上邊這段就是具體的入口。main直接調用了privateMain,在privateMain裏邊做具體的初始化工作。
第一步:
加載監聽器
第二步:
解釋命令行參數
第三步:
正式運行
看了這個短短几行代碼,冒出來幾個問題:
1)爲啥無端端要弄個privateMain?
看英文註釋,privateMain應該會被多個地方調用,但我仍覺得這個是多此一舉。
2)看起來listeners如果是在本地運行,應該永遠都是空纔是,那有啥用?
這個大致看了下,命令行方式的啓動,會在privateMain裏邊的configure函數做默認listeners的加載。如果在
命令行的xml指定了使用別的listeners,就會替換掉默認的。這個是testng靈活擴展的關鍵。
具體的listeners的加載跟定義。後邊結合testng的運行跟加載機制,詳細說明。