---
title: "在ant中使用junit命令跑所有测试"
author: "earl86"
date: "2008-10-29T17:40:00Z"
tags: ["Ant", "Apache", "Web", "junit", "log4j"]
slug: "ant-junit"
draft: false
lastmod: "2008-10-29T17:40:00Z"
id: 592210
url: "https://earl86.iteye.com/blog/592210"
---

&lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*编译测试文件\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;

&lt;target name="compile.functionalTest"&gt;  
        &lt;mkdir dir="${build.dir}/functionalTest"/&gt;  
        &lt;javac srcdir="${basedir}/functionTest" destdir="${build.dir}/functionalTest" classpathref="app.classpath"/&gt;  
    &lt;/target&gt;

&lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;  
     
    &lt;target name="run.selenium.tests" depends="compile.functionalTest"&gt;  
            &lt;mkdir dir="${basedir}/report" /&gt;  
           &lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*\*这些属性可以参看ant的文档\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;  
            &lt;junit printsummary="on" haltonfailure="false" failureproperty="functional.tests.failed"      showoutput="yes" reloading="false" fork="yes" forkmode="perBatch"&gt;  
                &lt;classpath&gt;  
                   &lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*\*这个路径指的是源文件编译后的class文件和配置文件\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;  
                    &lt;pathelement path="${build.dir}/dest/WEB-INF/classes" /&gt;  
                   &lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*\*这个路径指的是测试文件编译后class文件\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;  
                    &lt;pathelement path="${build.dir}/functionalTest"/&gt;  
    &lt;!--\*\*\*\*\*\*\*\*\*\*\*\*\*\*这个路径指的是依赖的jar包\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*--&gt;  
                    &lt;path refid="app.classpath" /&gt;  
                &lt;/classpath&gt;  
                &lt;formatter type="xml" /&gt;  
                 
                &lt;sysproperty key="log4j.configuration" value="log4j.properties" /&gt;  
                &lt;sysproperty key="org.apache.commons.logging.Log" value="org.apache.commons.logging.impl.NoOpLog" /&gt;  
                &lt;batchtest todir="${basedir}/report"&gt;  
                    &lt;fileset dir="${build.dir}/functionalTest"&gt;  
                        &lt;include name="\*\*/\*Test.class" /&gt;  
                    &lt;/fileset&gt;  
                &lt;/batchtest&gt;  
            &lt;/junit&gt;  
            &lt;fail if="functional.tests.failed" message="One or more tests failed. See test output for details" /&gt;  
        &lt;/target&gt;