【学习笔记】系列十六:Ant单元测试TestNG

来源:互联网 发布:地暖好吗知乎 编辑:程序博客网 时间:2024/06/04 00:35

最后的Ant,是TestNG

说实话TestNG的测试报告也不是很美观,所以引入了ReportNG,放心,这个只是个jar包,不需要做太多的其他操作

不过官方的ReportNG有一个中文显示乱码的bug,需要修改源码重新编译


TestNG自身的testng.xml就不说了,直接上Demo:

也是自己的代码,不怕丢人

<?xml version="1.0"?><project name="Demo" default="run" basedir="."><!-- 引入lib --><path id="run.classpath"><fileset dir="${basedir}"><include name="libs/*.jar" /></fileset></path><!-- 定义TestNG的Ant任务 --><taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="run.classpath" /><!-- 清理历史文件 --><target name="clean"><delete dir="build" /></target><!-- 编译 --><target name="compile" depends="clean"><echo message="mkdir" /><mkdir dir="build/classes" /><javac srcdir="src" destdir="build/classes" includeAntRuntime="false" debug="on" encoding="UTF-8"><classpath refid="run.classpath" /></javac><!-- 用到log4j配置的话,需要移入自定义的编译目录 --><copy todir="build/classes" file="${basedir}/src/log4j.properties" /></target><path id="runpath"><path refid="run.classpath" /><pathelement location="build/classes" /></path><!-- 用例执行 --><target name="run" depends="compile"><!-- 指定报告输出目录,指定用例执行时的listeners为ReportNG提供的 --><testng classpathref="runpath" outputDir="report/reportng/test-output" haltonfailure="true" useDefaultListeners="false" listeners="org.uncommons.reportng.HTMLReporter,org.testng.reporters.FailedReporter"><!-- 指定testng.xml --><xmlfileset dir="${basedir}" includes="testng.xml" /><jvmarg value="-Dfile.encoding=UTF-8" /><!-- 设定报告中的title --><sysproperty key="org.uncommons.reportng.title" value="Baidu Tests" /></testng></target></project>

报告格式如下,好看多了


0 0
原创粉丝点击