通过ant中的 junitreport task来生成JUnit测试报告,target的代码如下:
<target depends="build" name="AllTests"> <mkdir dir="${junit.output.dir}"/> <junit fork="yes" printsummary="withOutAndErr"> <formatter type="xml"/> <test name="com.fujitsu.netproto_knowhow.testcase.AllTests" todir="${junit.output.dir}"/> <classpath refid="netproto_knowhow.classpath"/> </junit> </target> <target name="junitreport" depends="AllTests"> <mkdir dir="${junit.output.report}"/> <junitreport todir="${junit.output.report}"> <fileset dir="${junit.output.dir}"> <include name="TEST-*.xml"/> </fileset> <report format="frames" todir="${junit.output.report}"/> </junitreport> </target>
可是,我在Eclipse中执行这个target的时候,却一直报下面这个错误
[junitreport] Processing F:\Workspaces\HTML5\netproto_knowhow\ant\junit\20130410092003\html\TESTS-TestSuites.xml to C:\Users\WANGZH~1\AppData\Local\Temp\null1293654028 [junitreport] Loading stylesheet jar:file:/F:/Development_Tools/eclipse-jee-juno-SR2-win32/plugins/org.apache.ant_1.8.3.v201301120609/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] : Error! The first argument to the non-static Java function 'replace' is not a valid object reference. [junitreport] : Error! Cannot convert data-type 'void' to 'reference'. [junitreport] : Fatal Error! Could not compile stylesheet [junitreport] Failed to process F:\Workspaces\HTML5\netproto_knowhow\ant\junit\20130410092003\html\TESTS-TestSuites.xml
Eclipse中,我的JRE版本是 1.6 U39,ant 版本是1.8.3,JUnit版本是4.10.
百度了很长时间,没有找到答案。
换谷歌,终于在stackoverflow上找到了一个解决方案:
http://stackoverflow.com/questions/10536095/ant-junit-build-error-inside-eclipse
按照上面的贴子中的想法,我变通了一下,将我自己的JRE版本换成了1.5的,便不会再现上面的这个问题。
但是,由于JUnit4.10与JRE5不兼容,所以,需要换成JUnit3,或者JUnit4的低版本。
大家也可以试试JRE6的低版本,比如,JRE6 u26 等等,也是可以的。
网上还有一种做法,就是不在Eclipse中执行ant,便没有这种问题,但是这种方法我没有试过。