ようこそ、皆さん

开心幸福生活每一天。。。

JPLT2が合格しましたが、会話と聴力はまだまだです。これからも、がんばれ!!!

用Ant编译、junit测试、生成测试报告、最终自动发mail

红色部分是自己所写,黑色部分是参照别人的。。。
测试通过的版本如下:
Eclipse:3.3.2
jdk:1.6
junit:3.8
ant:1.7(1.7之前的版本好像还不提供mail功能。。。)

<!-- JUnit build script using ant 1.7 -->
<project name="JunitTestProject" default="mail" basedir=".">
 <property name="app.name" value="JunitTestProject" />
 <property name="build.dir" value="bin" />

 <!-- ====================" path  define  " ================================ -->
 <path id="cobertura.classpath">
  <fileset dir="lib/coberture">
   <include name="cobertura.jar" />
   <include name="*.jar" />
  </fileset>
 </path>
 <!-- ====================" cobertura task define  " Target ================================ -->
 <taskdef classpathref="cobertura.classpath" resource="tasks.properties" />

 <!-- ==================== "clean " Target ================================ -->
 <target name="clean">
  <available property="junit.present" classname="junit.framework.TestCase" />
  <delete dir="${build.dir}" quiet="true" />
  <delete file="report" quiet="true" />
 </target>

 <!-- ==================== "copy xml resource " Target ================================ -->
 <target name="copyxml" depends="clean">
  <copy todir="${build.dir}/testcases">
   <fileset dir="WEB-INF" />
  </copy>
 </target>

 <!-- ==================== "compile  src" Target ================================ -->
 <target name="compile" depends="copyxml">
  <mkdir dir="${build.dir}" />
  <javac srcdir="src" destdir="${build.dir}" debug="yes">
   <classpath>
    <fileset dir="lib" casesensitive="yes">
     <include name="**/*.jar" />
    </fileset>
   </classpath>
   <include name="**/*.java" />
  </javac>
  <javac srcdir="WEB-INF" destdir="${build.dir}">
   <classpath>
    <fileset dir="lib" casesensitive="yes">
     <include name="**/*.jar" />
    </fileset>
   </classpath>
   <include name="*.jsp" />
  </javac>
 </target>

 <!-- ==================== jar" Target ================================ -->
 <target name="jar" depends="compile">
  <mkdir dir="dist/lib" />
  <jar jarfile="dist/lib/${app.name}.jar" basedir="${build.dir}" includes="com/**" />
 </target>

 <!-- ==================== compile test src" Target ================================ -->
 <target name="compiletests" depends="jar">
  <mkdir dir="${build.dir}/testcases" />
  <javac srcdir="test" destdir="${build.dir}/testcases" >
   <classpath>
    <fileset dir="lib" casesensitive="yes">
     <include name="**/*.jar" />
    </fileset>
    <fileset dir="dist/lib" casesensitive="yes">
     <include name="**/*.jar" />
    </fileset>
   </classpath>
   <include name="**/*.java" />
  </javac>
 </target>

 <!-- ==================== instrumented" Target ================================ -->
 <target name="instrumented" depends="compiletests">
  <cobertura-instrument todir="bin/instrumented-classes">
   <ignore regex="org.apache.log4j.*" />
   <fileset dir="bin">
    <include name="com/**/*.class" />
   </fileset>
  </cobertura-instrument>
 </target>

 <!-- ==================== junit-test" Target ================================ -->
 <target name="runtests" depends="instrumented">
  <mkdir dir="report" />
  <property name="tests" value="*Test" />
  <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">

   <formatter type="plain" usefile="false" />
   <formatter type="xml" />
   <batchtest todir="report">
    <fileset dir="test">
     <include name="**/${tests}.java" />
     <exclude name="**/ConfigTest.java" />
    </fileset>
   </batchtest>
   <!--
    Note the classpath order: instrumented classes are before the
    original (uninstrumented) classes.  This is important.
   -->
   <classpath location="bin/instrumented-classes" />
   <!--
    src classpath
   -->
   <classpath location="bin" />

   <!--
    The instrumented classes reference classes used by the
    Cobertura runtime, so Cobertura and its dependencies
    must be on your classpath.
   -->
   <classpath refid="cobertura.classpath" />
   <!--
    test case class path define
   -->
   <classpath>
    <fileset dir="lib" casesensitive="yes">
     <include name="**/*.jar" />
    </fileset>
    <pathelement location="bin/testcases" />
   </classpath>
  </junit>
 </target>

 <!-- ==================== junit-report" Target ================================ -->
 <target name="report" depends="runtests">
  <mkdir dir="report/html" />
  <junitreport todir="report">
   <fileset dir="report">
    <include name="TEST-*.xml" />
   </fileset>
   <report todir="report/html" />
  </junitreport>
 </target>


 <!-- ==================== "coverage-report" Target ================================ -->
 <target name="coverage-report" depends="report">
  <cobertura-report format="html" destdir="cobertura" >
   <fileset dir="src">
    <include name="**/*.java" />
   </fileset>
  </cobertura-report>
  <echo>The execution of coverage-report is complete. Coverage Reports are available in /${coverage-report}</echo>
 </target>
 
 <!-- ==================== "make file to zip" Target ================================ -->
 <target name="make_data_zip" depends="coverage-report">
  <tstamp>
   <format property="date" pattern="yyyy-MM-dd HH-mm" />
  </tstamp>
  <jar jarfile="dist/lib/cobertura${date}.zip" basedir="cobertura" />
  <jar jarfile="dist/lib/report${date}.zip" basedir="report" excludes="*.xml"/>
 </target>

<!-- ==================== "mail" Target ================================ -->
 <target name="mail" depends="make_data_zip">
  <!-- <taskdef name="mail" classname="org.apache.tools.ant.taskdefs.optional.mail.MimeMail"/> -->
  <tstamp/>
  <mail messageMimeType="text/html"
                    messageFile="message.txt"
                    tolist="
bpcjy@hotmail.com"
                    mailhost="mailsvr or mail IPAddress"
                    subject="JUnit Test Results: ${TODAY}"
                    from="
bpcjy@hotmail.com">
   <fileset dir=".">
    <include name="dist/lib/*.zip"/>
   </fileset>
  </mail>
 </target>

</project>



快快乐乐、认认真真生活才是真。

posted on 2009-03-13 14:32 鮑佩 阅读(3540) 评论(3)  编辑  收藏 所属分类: ant

评论

# re: 用Ant编译、junit测试、生成测试报告、最终自动发mail 2009-03-16 12:20 XXXXXXXXXXXX

狗屎 干嘛学日语  回复  更多评论   

# re: 用Ant编译、junit测试、生成测试报告、最终自动发mail 2009-03-17 14:51 anti-cpc

楼上正白痴。 别人学日语干你X事,死粪粪  回复  更多评论   

# re: 用Ant编译、junit测试、生成测试报告、最终自动发mail 2015-02-03 15:24 谢霆锋

关你篮子事  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
平平淡淡,认认真真生活才是真。