ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Leftwich <>
Subject Re: junit and log4j within ant
Date Sat, 05 May 2001 20:19:36 GMT
At 05:06 PM 04-05-01 -0400, William Surowiec wrote:
>I've searched about 3,000+ emails from this support group and have not 
>found information on the following:
>I am using ant 1.3 beta 3, junit3.6, log4j 1.0.4, and jedit 3.1 final 
>(maybe something in the mix is acting up).
>Anyway, I can use the java task to invoke an app and pass to it a 
>configuration file for log4j. Everything behaves as I expect.
>When I try to use a junit task to actually run the tests I am running in 
>the java task - some wheels seem to fall off. First, I do
>not see how I can pass an arg value (the config file for log4j) to the 
>class under test.

You can set system properties in the junit task prior to running junit 
using the following :

     <junit printsummary="yes" haltonfailure="no" fork="yes" 

       <sysproperty key="log4j.configuration" 

As an aside I find the following generic junit task (from Mike Clark 
<> on the junit mailing list) for calling a specified 
test case very useful :

          Test Case

          Use: ant -Dtestcase=com.whatever.TestCaseName
      <target name="" if="testcase" depends="compile.tests"
          description="Runs the specified JUnit test case">

          <junit printsummary="no" haltonfailure="yes">
                  <path refid="project.classpath" />
                  <pathelement path="${classes.dir}" />
              <formatter type="plain" usefile="false" />
              <test name="${testcase}" />


>More importantly, when I try to pass the value by coding it within the 
>class it seems I cannot create an "appender" (this is an
>output handler (as I understand it) within log4j).

What exactly do you mean by 'coding it within the class' - are you hard 
coding the value for the log4j.configuration file name, or are you calling 
PropertConfigurator.configure('file') or are you just calling the 
BasicConfigurator.configure(). Does this code work when you use the java 
task to invoke the app ?
In my setup I rely on log4j's default mechanism for locating and using the 
configuration file (which is documented on the log4j web sites version of 
the introductory manual, but not in the version included with the v1.0.4 
distribution) and find that by using the above sysproperty it all works 
very seamlessly.



View raw message