Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209314
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: Java

2011-04-07 11:18:58

  1. /* src/HelloWorldTest.java*/
  2. public class HelloWorldTest extends junit.framework.TestCase {
  3.     public void testNothing() {
  4.     }
  5.       public void testWillAlwaysFail() {
  6.         fail("An error message");
  7.     }
  8. }
build.xml:
  1. <project name="HelloWorld" basedir="." default="main">

  2.   <property name="src.dir" value="src"/>
  3.   <property name="build.dir" value="build"/>
  4.   <property name="classes.dir" value="${build.dir}/classes"/>
  5.   <property name="jar.dir" value="${build.dir}/jar"/>
  6.     <property name="lib.dir" value="lib"/>
  7.   <property name="report.dir" value="${build.dir}/junitreport"/>

  8.     <path id="classpath">
  9.         <fileset dir="${lib.dir}" includes="**/*.jar"/>
  10.     </path>
  11.     <path id="application">
  12.             <fileset dir="${jar.dir}" includes="${ant.project.name}.jar"/>
  13.     </path>
  14.   <property name="main-class" value="oata.HelloWorld"/>

  15.   <target name="clean">
  16.     <delete dir="${build.dir}"/>
  17.   </target>

  18.   <target name="compile">
  19.     <mkdir dir ="${classes.dir}"/>
  20.     <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
  21.     <copy todir="${classes.dir}">
  22.         <fileset dir="${src.dir}" excludes="**/*.java"/>
  23.     </copy>
  24.   </target>

  25. <target name="jar" depends="compile">
  26.   <mkdir dir="${jar.dir}"/>
  27.   <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
  28.     <manifest>
  29.       <attribute name="Main-Class" value="${main-class}"/>
  30.     </manifest>
  31.   </jar>
  32. </target>

  33. <target name="run" depends="jar">
  34.   <java fork="true" classname="${main-class}">
  35.     <classpath>
  36.         <path refid="classpath"/>
  37.                 <path refid="application"/>
  38.     </classpath>
  39.   </java>
  40. </target>

  41. <target name="junit" depends="jar">
  42.     <mkdir dir="${report.dir}"/>
  43.         <junit printsummary="yes">
  44.             <classpath>
  45.                 <path refid="classpath"/>
  46.                 <path refid="application"/>
  47.             </classpath>
  48.            <formatter type="xml"/>

  49.             <batchtest fork="yes" todir="${report.dir}">
  50.                 <fileset dir="${src.dir}" includes="*Test.java"/>
  51.             </batchtest>
  52.         </junit>
  53.     </target>

  54. <target name="junitreport">
  55.     <junitreport todir="${report.dir}">
  56.         <fileset dir="${report.dir}" includes="TEST-*.xml"/>
  57.         <report todir="${report.dir}"/>
  58.     </junitreport>
  59. </target>

  60. <target name="clean-build" depends="clean,jar"/>

  61. <target name="main" depends="clean,run"/>

  62. </project>
阅读(483) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~