junit 输出html格式的测试报告

junit 输出html格式的测试报告

有些人会碰到这些问题.可能是ant或者java的bug,

[junitreport] Loading stylesheet jar:file:/D:/myname/research/android/eclipse-jee-indigo-withADT/eclipse-jee-indigo/eclipse/plugins/org.apache.ant_1.8.2.v20110505-1300/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] : Error! 非 static Java 函数“replace”的第一个自变量不是有效的对象参考。
[junitreport] : Error! 无法将数据类型“void”转换成“reference”。
[junitreport] : Fatal Error! 无法编译样式表

请参考
http://stackoverflow.com/questions/10536095/ant-junit-build-error-inside-eclipse

解决方法:

1. 升级到最新的jdk

2.  stackoverflow上说, 是因为ant的bug。 所以请升级到1.9 ,  针对于eclipse 4.4 版本的,请升级ant 到1.9.1 。

具体的build.xml 配置

<target name="test" depends="compile">     
  <mkdir dir="build/report/junit"/>
	<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
	    		    			<classpath>
	<path refid="classpath"/>
	</classpath>
</taskdef>
	  <junit fork="no" dir="."  failureProperty="test.failed" showoutput="yes" printsummary="on">
		<classpath location="build/classes" />
		<classpath refid="classpath" />

<formatter type="xml" />
	<batchtest todir="build/report">
	  <fileset dir="src">
	<include name="**/YoursuiteName.java" />
	  </fileset>
	</batchtest>
	  </junit>			  
		  <junitreport todir="build/report">
  <fileset dir="build/report"> 
  <include name="TEST-*.xml"/>
  </fileset> 
 <report format="frames" todir="build/report/html"/></junitreport>
		</target>

此篇文章已被阅读4275 次

Tags:

Add a Comment

邮箱地址不会被公开。 必填项已用*标注