應項目需求,用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>