[英]getPackage() returning null when my JUnit test is run from Ant
[英]Is there a way to tell whether a JUnit test is being run from Ant?
我想在運行時識別我的JUnit
測試是否從ant
運行。 原因是,如果它是從ant
運行的,我想將信息記錄到日志文件中,否則,我只想寫標准輸出。
Ant的內置JUnit Task具有showoutput
屬性,該屬性會將測試產生的所有輸出發送到ant的日志系統。
另請參見此 SO問題ant junit任務不報告有關報告選項的詳細信息。
一種實現方法是在Ant腳本的junit任務中包含一個屬性:
<junit fork="yes">
<jvmarg value="-Druntime.agent=ANT"/>
...
</junit>
然后,在您的JUnit測試工具中,查詢該屬性的存在和/或屬性:
String agent = System.getProperty("runtime.agent");
if ("ANT".equals(agent)) {
// set up file logging
} else {
// set up STDOUT logging
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.