2012-01-25 64 views
0

我已經在這個問題上被擊中了過去兩年days.Please幫我在這。我正在使用ANT運行我的JUNIT腳本。正在生成報告,但ANT無法找到我的log4j.properites文件。當我通過eclipse運行時,正在生成日誌。我在這裏的問題是我想通過ANT.DO運行日誌時需要設置任何屬性。 什麼是我做錯誤?螞蟻是不承認Log4j.properties文件

請幫幫我。


我的日誌:

#Application Logs 
#log4j.logger.devpinoyLogger 
log4j.rootLogger=DEBUG, dest1 
log4j.appender.dest1=org.apache.log4j.RollingFileAppender 
log4j.appender.dest1.maxFileSize=5000KB 
log4j.appender.dest1.maxBackupIndex=3 
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout 
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n 
log4j.appender.dest1.File=/Users/Application.log 
#do not append the old file. Create a new log file everytime 
log4j.appender.dest1.Append=false 

build.xml 


<?xml version="1.0" encoding="iso-8859-1"?> 
<!DOCTYPE project [ 
]> 

<project name="Module_Junit_Ant" default="usage" basedir="."> 

<!-- ========== Initialize Properties =================================== --> 
    <property environment="env"/> 

    <property name="ws.home" value="${basedir}"/> 
    <property name="ws.jars" value="${ws.home}/jars"/> 
    <property name="test.dest" value="${ws.home}/build"/> 
    <property name="test.src" value="${ws.home}/src"/> 
    <property name="test.reportsDir" value="${ws.home}/reports"/> 



    <path id="testcase.path"> 


     <pathelement location="${test.dest}"/> 

     <fileset dir="${ws.jars}"> 
      <include name="*.jar"/> 
     </fileset> 

     </path> 


    <!--target name="start-selenium-server"> 
     <java jar="${ws.home}/lib/selenium-server.jar"/> 
    </target--> 

    <target name="setClassPath" unless="test.classpath"> 
     <path id="classpath_jars"> 
      <fileset dir="${ws.jars}" includes="*.jar"/> 
      <fileset dir="${test.src}" includes="*.properties"/> 
     </path> 
     <pathconvert pathsep=":" 
      property="test.classpath" 
      refid="classpath_jars"/> 
    </target> 

    <target name="init" depends="setClassPath"> 
     <tstamp> 
      <format property="start.time" pattern="MM/dd/yyyy hh:mm aa" /> 
     </tstamp> 
     <condition property="ANT" 
      value="${env.ANT_HOME}/bin/ant.bat" 
      else="${env.ANT_HOME}/bin/ant"> 
        <os family="windows" /> 
     </condition> 

    </target> 

    <!-- all --> 
    <target name="all"> 
    </target> 

    <!-- clean --> 
    <target name="clean"> 
     <delete dir="${test.dest}"/> 
    </target> 

    <!-- compile --> 
    <target name="compile" depends="init, clean" > 
     <delete includeemptydirs="true" quiet="true"> 
      <fileset dir="${test.dest}" includes="**/*"/> 
     </delete> 
     <echo message="making directory..."/> 
     <mkdir dir="${test.dest}"/> 
     <echo message="classpath------: ${test.classpath}"/> 
     <echo message="compiling..."/> 
     <javac 
      debug="true" 
      destdir="${test.dest}" 
      srcdir="${test.src}" 
      target="1.5" 
      classpath="${test.classpath}" 
     > 
     </javac> 
     </target> 

    <!-- build --> 
    <target name="build" depends="init"> 
    </target> 




    <target name="usage"> 
     <echo> 
      ant run will execute the test 
     </echo> 
    </target> 

    <path id="test.c"> 
      <fileset dir="${ws.jars}" includes="*.jar"/> 
    </path> 



    <target name="run" > 
     <delete includeemptydirs="true" quiet="true"> 
        <fileset dir="${test.reportsDir}" includes="**/*"/> 
       </delete> 
       <java jar="${ws.jars}" fork="true" spawn="true" /> 
       <junit fork="yes" haltonfailure="no" printsummary="yes"> 
        <classpath refid="testcase.path" /> 

        <!-- <classpath ="${test.classpath}"/> --> 
       <batchtest todir="${test.reportsDir}" fork="true"> 
       <fileset dir="${test.dest}"> 

        <include name="LogTest.class" /> 
        <!--include name="tests/suite1/FirstSuiteRunner.class" /> 
        <include name="tests/suite1/FirstSuiteRunner.class" /--> 


       </fileset> 
       </batchtest>  
        <formatter type="xml" /> 
        <classpath refid="testcase.path" /> 
      </junit> 
       <junitreport todir="${test.reportsDir}">  
        <fileset dir="${test.reportsDir}"> 
         <include name="TEST-*.xml" /> 
        </fileset> 
        <report todir="${test.reportsDir}" /> 
       </junitreport> 
      </target> 

     <target name="email" > 
       <java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" /> 
     </target> 


</project> 
+0

哪裏是你的log4j.properties? – oers

+0

見http://stackoverflow.com/questions/1284952/why-isnt-my-log4j-properties-file-getting-used。這可能是因爲你的log4j文件不在類路徑中。 – Jayan

回答

0

凡均位於log4j.properties? 我什麼工作是把一個

< pathelement location="x/y/z"/>

< path id="testcase.path">

指向包含一個log4j.properties的文件夾裏面! 因此,在這個例子中你的log4j.properties應該是「z」的文件夾內!