I am using Ant's <junit> task to run my JUnit tests, which happen to have log4j statements. Currently, my log.properties file is outputting the logs to the console.

Inside the <junit> task, I am using <batchtest> to capture test results into XML test reports. Currently, it is capturing the System.out lines from my program fine. It can even capture any System.out lines I put into my test cases. But it fails to capture the log4j statements from my test cases (even though I configured my log4j to output to the console).

When I run ant, the System.out lines do not appear on the console (which is fine with me), but show up in the XML test reports (which is what I want). Meanwhile, the log4j statements DO show up on the console (which is fine), but NOT in the XML test reports (this is my question).

How can I get the log4j statements that are printing to the console into the XML test reports?

I searched the web, and found a thread with a similar problem:
http://groups.yahoo.com/group/junit/message/13029?threaded=1

Users in that group said to ask the Ant group. Then, the original poster eventually proposed a workaround, which was to turn off the fork attribute. I tried this workaround, and it works for me. However, in some cases, I need forking on because I want to run the test in a different directory, like in the example below with ${build.dir}. Or, I need to feed in JVM arguments, like increasing the memory -Xmx and stuff.

So, is there a way to capture the log4j console statements while still enabling forking?



Here is the relevant part of my build.xml:
<junit printsummary="yes" fork="yes" dir="${build.dir}" haltonfailure="no">
   <classpath refid="classpath" />
   <formatter type="xml" />
   <batchtest todir="${log.dir}/xml">
       <fileset dir="${build.dir}">
           <include name="**/*Test*" />
       </fileset>
   </batchtest>
</junit>

Here is the contents of my log.properties:
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] (%F:%L) - %m%n



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to