Reputation:
I want to recognize at runtime whether my JUnit
tests are being run from ant
or not. The reason for this is, if it's being run from ant
, I want to log information to a log file, else I just want to write to standard out.
Upvotes: 0
Views: 55
Reputation: 31648
Ant's built in JUnit Task has a showoutput
attribute which will send any output produced from the tests to ant's logging system.
See also this SO question ant junit task does not report detail about reporting options.
Upvotes: 1
Reputation: 10984
One way to accomplish this would be to include a property in the junit task in the Ant script:
<junit fork="yes">
<jvmarg value="-Druntime.agent=ANT"/>
...
</junit>
Then, in your JUnit test harness inquire about the existence and/or property for that property:
String agent = System.getProperty("runtime.agent");
if ("ANT".equals(agent)) {
// set up file logging
} else {
// set up STDOUT logging
}
Upvotes: 0