- 自动化单元测试可以使用maven或者直接使用ant来做,由于项目中没有使用maven,我们这里使用了ant
- 下面贴出单元测试的build.xml
<?xml version="1.0"?>
<!-- =============================================
auto unittest task
========================================== -->
<project name="auto unittest task" default="junit and report" basedir=".">
<property name="output folder" value="back-end/SztbService/out/war_exploded/WEB-INF/classes"/>
<property name="report folder" value="report" />
<property name="build.testcase.dir" value="${output folder}" />
<path id="ref-lib">
<pathelement location="${build.testcase.dir}" />
<fileset dir="back-end/SztbService/out/war_exploded/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="back-end/SztbService/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="test init">
<mkdir dir="${report folder}"/>
</target>
<!-- ========================================
target: auto test all test case and output report file
===================================== -->
<target name="junit and report" depends="test init">
<junit printsummary="on" fork="true" showoutput="true">
<classpath refid="ref-lib" />
<formatter type="xml" />
<batchtest todir="${report folder}">
<fileset dir="${build.testcase.dir}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${report folder}">
<fileset dir="${report folder}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${report folder}" />
</junitreport>
</target>
<target name="clean" description="Deletes compiled and generated code">
<delete dir="${report folder}"/>
</target>
</project>
- 将测试结果输出到了${report folder}中,这里的${report folder}为report目录,注意ref-lib中不要忘记引入junit的jar包
- 在构建中执行junit.xml
- 然后增加构建后操作Publish JUnit test result report
- 保存并构建后,即可看到测试结果及趋势图
时间: 2024-10-13 02:31:40