ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Leftwich <digi...@ix.net.au>
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:
>Hi,
>
>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" 
dir="${unit.test.dir}">

       <sysproperty key="log4j.configuration" 
value="file:${unit.test.conf}/log4j.properties"/>
       ...
     </junit>

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

      <!--
          Test Case

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

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

      </target>


>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.

HTH

Robert


Mime
View raw message