Hi Mark,

Thanks for sharing your tip.  I read your link,

To get the output from these logging statements to appear in your JUnit
report (TEST-package.TestFoo.xml) generated for the test TestFoo.java,
you need the following log4j configuration stuff in TestFoo.jar.[.java?]

A static reference to the logger used inside of Foo.java ...

private static Logger logOfClassBeingTested = Logger.getLogger(Foo.class);

Then, you do add an appender in the setup() method, which you have to remove in teardown(), otherwise, you end up with multiple appenders.


Wouldn't it work if you just put that setup() code into the TestFoo constructor instead? That way, you don't need to do the stuff in teardown(), right?

Or am I missing something?

Oski

From: Mark Hansen <[EMAIL PROTECTED]>
Reply-To: "Ant Users List" <user@ant.apache.org>
To: Ant Users List <user@ant.apache.org>
Subject: RE: JUnit, ANT, log4j, System.out issue
Date: Fri, 25 Mar 2005 11:53:26 -0800 (PST)

I ran into this same problem (but in the context of
using Maven).  The problem is that JUnit redirects
STDOUT *AFTER* the log4j configuration has taken
place.

If you want your log4j console appender output to go
to the same place that JUnit sends STDOUT, you need to
create the log4j console appender and add it to the
Logger instance you are using at runtime.

Here is how I did it in the Maven context ->
http://mail-archives.eu.apache.org/mod_mbox/maven-users/200503.mbox/[EMAIL 
PROTECTED]

--- "Raymond K. DeCampo" <[EMAIL PROTECTED]>
wrote:

> Anybody? Anybody? Bueller?
>
> Seriously, I'd at least appreciate any
> insight/speculation as to where the problem might
> be.  If nobody knows exactly what is going on I'll
> have to look at the source and it would be nice to
> have some opinions about where to start (e.g. ANT vs
> JUnit, specific modules/classes, etc.).
>
> Thanks,
>
> Raymond DeCampo
> Software Architect
> PROMERGENT
> 5010 Campuswood Drive - East Syracuse NY 13057
> 315.414.9855 x411 || 315-414-9856 f
> http://www.promergent.com
>
> PEOPLE . PROCESS . DATATM
> This electronic transmission contains information
> from Progressive Software Solutions, Inc. (d/b/a
> ProSoft, d/b/a PROMERGENT), which may be company
> confidential and/or company private. The information
> contained herein is intended for the exclusive use
> of the addressee named above. If you are not the
> intended recipient, be aware that any disclosure,
> copying, distribution or use of this information is
> prohibited. If you have received this electronic
> mail transmission in error, please notify us by
> telephone or by electronic mail.
>
>
>
> -----Original Message-----
> From: Raymond K. DeCampo
> Sent: Monday, March 21, 2005 09:23
> To: user@ant.apache.org
> Subject: JUnit, ANT, log4j, System.out issue
>
>
> Hello,
>
> I am experiencing an issue with the combination of
> ANT, JUnit and
> log4j. Here's the situation. The ANT build file uses
> the <junit>
> task. Log4j is configured to print to the console.
> There are also
> times when the unit tests use System.out directly.
> The problem is
> that the log4j statements are not captured by the
> <junit> as part of
> the standard output. The logging statements do
> appear on the console
> when I run the tests. But since they are not
> captured by <junit>,
> they do not appear in the XML files and are lost
> forever.
>
> I originally posted this message to the JUnit list.
> Since then I have
> discovered that if I do not fork the JUnit process
> everything behaves
> as I expect.  Not forking the JUnit process is not
> really an option,
> as there are quite a few unit tests and I run into
> memory issues.
>
> Here's the ANT target:
>
> <target name="run-test" depends="init,test-setup">
> <!-- execute the test -->
> <junit fork="yes"
>        dir="${basedir}"
>        haltonfailure="${test.halt.on.failure}"
>        printsummary="withOutAndErr">
>     <classpath refid="test.classpath" />
>     <formatter type="xml" />
>     <formatter type="plain" usefile="false"/>
>     <jvmarg line="${test.jvmargs}" />
>     <batchtest fork="yes"
> todir="${test.report.xml.dir}">
>         <fileset dir="${test.src}" >
>             <include name="${test.full.includes}" />
>             <exclude name="${test.full.excludes}" />
>         </fileset>
>     </batchtest>
> </junit>
> </target>
>
> Here's the log4j configuration:
>
> <log4j:configuration debug="false">
> <appender name="SYS_OUT"
> class="org.apache.log4j.ConsoleAppender">
>     <param name="Target" value="System.out"/>
>     <layout class="org.apache.log4j.PatternLayout">
>         <param name="ConversionPattern" value="%-5p
> %c{2} -%m%n"/>
>     </layout>
> </appender>
>
> <root>
>     <level value="INFO"/>
>     <appender-ref ref="SYS_OUT"/>
> </root>
> </log4j:configuration>
>
> Version information:
> [09:19 C:/] ant -version
> Apache Ant version 1.6.0 compiled on December 18
> 2003
> log4j 1.2.8
> JUnit 3.8.1
>
> If anybody could enlighten me on the subject, I'd
> appreciate it.
>
> Thanks,
>
> Raymond DeCampo
> Software Architect
> PROMERGENT
> 5010 Campuswood Drive - East Syracuse NY 13057
> 315.414.9855 x411 || 315-414-9856 f
> http://www.promergent.com
>
> PEOPLE . PROCESS . DATATM
> This electronic transmission contains information
> from Progressive Software Solutions, Inc. (d/b/a
> ProSoft, d/b/a PROMERGENT), which may be company
> confidential and/or company private. The information
> contained herein is intended for the exclusive use
> of the addressee named above. If you are not the
> intended recipient, be aware that any disclosure,
> copying, distribution or use of this information is
> prohibited. If you have received this electronic
> mail transmission in error, please notify us by
> telephone or by electronic mail.
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
>


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




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



Reply via email to