应项目需求,用junit写了个接口测试
又要求部署到jenkins上,打包之前用ant跑一遍测试用例
于是,ant小白折腾了一个礼拜,终于搞定
期间遇到了各种问题,修改了无数次build.xml。最终版build.xml如下
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<project name="E7-Planning" default="junit" basedir=".">
<!-- ================================================ -->
<!-- 变量设置 -->
<!-- ================================================ -->
<!-- 源代码src路径 -->
<property name="src.path" value="${basedir}\src"/>
<!-- 编译文件class路径 -->
<property name="build.path" value="${basedir}\build"/>
<!--测试代码路径-->
<property name="test.path" value="${basedir}\test"/>
<!--lib包路径-->
<property name="lib.path" value="${basedir}\WebContent\WEB-INF\lib"/>
<!-- resource -->
<property name="resource.path" value="${basedir}\resource"/>
<!-- 生成报告junit.xml路径 -->
<property name="report.path" value="${basedir}\report"/>
<!-- ant -->
<property name="ant.path" value="C:\install\apache-ant-1.10.1\lib"/>
<property name="run.jvmargs.ide" value=""/>
<!-- ================================================ -->
<!-- 设置classpath -->
<!-- ================================================ -->
<path id="compile.path">
<fileset dir="${lib.path}">
<include name="**\*.jar"/>
</fileset>
<fileset dir="${ant.path}">
<include name="**\*.jar"/>
</fileset>
<pathelement path="compile.path"/>
</path>
<!-- ============================================== -->
<!-- 清除历史编译class -->
<!-- ============================================== -->
<target name="clean" description="clean">
<delete dir="${build.path}"/>
</target>
<target name="mkdir" depends="clean" description="创建初始化目录结构" >
<echo message="mkdir"/>
<mkdir dir="${build.path}/classes" />
<mkdir dir="${report.path}" />
</target>
<!-- ============================================== -->
<!-- 编译测试文件,初始化目录 -->
<!-- ============================================== -->
<target name="compile" description="mkdir">
<echo message="begin compile..."/>
<javac srcdir="${src.path}" destdir="${build.path}/classes" classpathref="compile.path" includeantruntime="true" encoding="UTF-8" nowarn="on"/>
<javac srcdir="${test.path}" destdir="${build.path}/classes" classpathref="compile.path" includeantruntime="true" encoding="UTF-8" nowarn="on">
<compilerarg value="-XDignore.symbol.file"/>
</javac>
<copy todir="${build.path}/classes">
<fileset dir="${resource.path}">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<include name="**/*.data"/>
<include name="**/*.license"/>
</fileset>
</copy>
<echo message="end compile..."/>
</target>
<!-- ============================================== -->
<!-- 打包 -->
<!-- ============================================== -->
<!-- <target name="jar" depends="compile">
<jar destfile="resource.jar" basedir="${resource.path}"/>
<copy todir="${lib.path}\WEB-INF\lib">
<fileset dir="${resource.path}">
<include name="resource.jar"/>
</fileset>
</copy>
</target> -->
<!-- ============================================== -->
<!-- 执行测试案例 -->
<!-- ============================================== -->
<target name="junit" depends="clean,mkdir,compile">
<junit fork="no" printsummary="true" showoutput="yes">
<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.path}/classes"/>
<path refid="compile.path"/>
</classpath>
<test name="com.epoch.planning.usecase.UseCase" todir="${report.path}" fork="no"/>
</junit>
</target>
<!-- 产生测试报告文档 -->
<target name="delete">
<delete dir="${report.path}"/>
</target>
</project>