Ant与Junit配合来实现自动化测试
2013-12-18 17:04
337 查看
看的教程中的案例代码,感觉太棒了!之前为什么不知道Ant有这么强大,因为之前都是一个人在战斗
,下面是Ant与Junit配合实现了自动化测试盒生成测试文档的代码!
<?xml version="1.0" encoding="UTF-8"?>
<project name="junit-test">
<property name="src.dir" location="src"></property>
<property name="test.src.dir" location="test"></property>
<property name="lib.dir" location="lib"></property>
<property name="build.dir" location="build"></property>
<property name="build.classes" location="${build.dir}/classes"></property>
<property name="build.test.dir" location="${build.dir}/test"></property>
<property name="build.test.classes" location="${build.test.dir}/classes"></property>
<property name="build.test.report" location="${build.test.dir}/report"></property>
<property name="run.test.class" value="**/Test*.class"></property>
<path id="compile-path">
<fileset dir="${lib.dir}" includes="*.jar"></fileset>
</path>
<path id="compile-test-path">
<path refid="compile-path"></path>
<pathelement location="${build.classes}"/>
</path>
<path id="run-test-path">
<path refid="compile-test-path"></path>
<pathelement location="${build.test.classes}"/>
</path>
<target name="clean">
<echo>进行项目的清理工作</echo>
<delete dir="${build.dir}"></delete>
</target>
<target name="init">
<echo>进行项目的初始化</echo>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.test.dir}"/>
<mkdir dir="${build.test.classes}"/>
<mkdir dir="${build.test.report}"/>
</target>
<target name="compile" depends="init">
<echo>编译源文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${src.dir}" destdir="${build.classes}" classpathref="compile-path"></javac>
</target>
<target name="compile-test" depends="compile">
<echo>编译测试文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${test.src.dir}" destdir="${build.test.classes}" classpathref="compile-test-path"/>
</target>
<target name="run-test" depends="compile-test">
<echo>运行单元测试</echo>
<junit printsummary="false" haltonfailure="false">
<classpath refid="run-test-path"></classpath>
<formatter type="brief" usefile="false"/>
<!--<test name="${run.test.class}"></test>-->
<formatter type="xml"/>
<batchtest todir="${build.test.report}">
<fileset dir="${build.test.classes}" includes="${run.test.class}"></fileset>
</batchtest>
</junit>
<junitreport todir="${build.test.report}">
<fileset dir="${build.test.report}" includes="TEST-*.xml"></fileset>
<report format="frames" todir="${build.test.report}/html"/>
</junitreport>
</target>
<target name="end" depends="run-test">
<echo>整个过程结束</echo>
</target>
</project>
,下面是Ant与Junit配合实现了自动化测试盒生成测试文档的代码!
<?xml version="1.0" encoding="UTF-8"?>
<project name="junit-test">
<property name="src.dir" location="src"></property>
<property name="test.src.dir" location="test"></property>
<property name="lib.dir" location="lib"></property>
<property name="build.dir" location="build"></property>
<property name="build.classes" location="${build.dir}/classes"></property>
<property name="build.test.dir" location="${build.dir}/test"></property>
<property name="build.test.classes" location="${build.test.dir}/classes"></property>
<property name="build.test.report" location="${build.test.dir}/report"></property>
<property name="run.test.class" value="**/Test*.class"></property>
<path id="compile-path">
<fileset dir="${lib.dir}" includes="*.jar"></fileset>
</path>
<path id="compile-test-path">
<path refid="compile-path"></path>
<pathelement location="${build.classes}"/>
</path>
<path id="run-test-path">
<path refid="compile-test-path"></path>
<pathelement location="${build.test.classes}"/>
</path>
<target name="clean">
<echo>进行项目的清理工作</echo>
<delete dir="${build.dir}"></delete>
</target>
<target name="init">
<echo>进行项目的初始化</echo>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.test.dir}"/>
<mkdir dir="${build.test.classes}"/>
<mkdir dir="${build.test.report}"/>
</target>
<target name="compile" depends="init">
<echo>编译源文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${src.dir}" destdir="${build.classes}" classpathref="compile-path"></javac>
</target>
<target name="compile-test" depends="compile">
<echo>编译测试文件</echo>
<javac failonerror="true" includeantruntime="true" srcdir="${test.src.dir}" destdir="${build.test.classes}" classpathref="compile-test-path"/>
</target>
<target name="run-test" depends="compile-test">
<echo>运行单元测试</echo>
<junit printsummary="false" haltonfailure="false">
<classpath refid="run-test-path"></classpath>
<formatter type="brief" usefile="false"/>
<!--<test name="${run.test.class}"></test>-->
<formatter type="xml"/>
<batchtest todir="${build.test.report}">
<fileset dir="${build.test.classes}" includes="${run.test.class}"></fileset>
</batchtest>
</junit>
<junitreport todir="${build.test.report}">
<fileset dir="${build.test.report}" includes="TEST-*.xml"></fileset>
<report format="frames" todir="${build.test.report}/html"/>
</junitreport>
</target>
<target name="end" depends="run-test">
<echo>整个过程结束</echo>
</target>
</project>
相关文章推荐
- Ant+junit的测试自动化
- Ant+junit的测试自动化
- 利用ant和junit实现单元测试的自动化
- Ant build.xml 模版 (JUnit)自动化 增量测试
- linux下使用ant+Jmeter+Jenkins实现接口测试自动化
- Ant+junit的测试自动化
- 使用Ant与Junit进行自动化测试
- Ant+Jmeter+Jenkins实现接口测试自动化
- eclipse下利ant、junit进行自动化测试例子(源码)
- ant+junit实现TDD,自动测试
- Ant+Jmeter+Jenkins实现接口测试自动化
- ant 学习(3)--结合junit形成自动化测试小框架
- 用Ant自动测试JUnit(Ant测试自动化--上)
- 利用ant和junit实现单元测试的自动化
- 用Ant自动测试JUnit(Ant测试自动化--上)
- ant+jmeter+crontab实现自动化性能测试
- Ant+Jmeter+Jenkins实现接口测试自动化
- 使用Ant+JUnit+Cobertura来实现代码覆盖自动测试
- 4000 利用ant和junit实现单元测试的自动化
- Ant+junit的测试自动化