【发布时间】:2011-06-16 07:51:33
【问题描述】:
<junit printsummary="on" fork="yes" forkmode="once"
haltonerror="false" haltonfailure="false"
failureproperty="junit.failure" showoutput="false" maxmemory="1024m">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
<dirset dir="${TEST_BUILD_DIR}"/>
</classpath>
<batchtest fork="no" todir="${TEST_BUILD_DIR}">
<fileset dir="${COMP_TEST_SRC}">
<include name="**/*Test.java" />
<include name="**/Test*.java" />
<exclude name="**/EswTestCase.java" />
</fileset>
</batchtest>
<formatter type="xml" />
</junit>
生成 xml 报告需要花费大量时间,并且会出现以下错误:
Caught an exception while logging the end of the build. Exception was:
java.lang.OutOfMemoryError: PermGen space
为什么生成 xml 需要很长时间?如何解决此错误并使应用程序快速运行。我最多只有 10 个测试文件。我使用命令提示符来执行 ant 脚本。
分析:
1) 如果我只为扩展 Junit 测试的测试类运行批处理测试,它执行得非常快。例如:
公共类 ImpactsParserTest 扩展 测试用例{..
2)现在,如果我有一个扩展 spring junit 测试的测试类:
公共类 AddressLookupServiceTest 扩展 EswTestCase{..
公共类 EswTestCase 扩展 AbstractDependencyInjectionSpringContextTests{..
这会导致 junit 目标运行非常缓慢并导致内存不足错误。为什么会这样?
3) 当我使用 batchtest fork="yes" 而不是 no 时,构建速度很快并且不会导致内存不足。但是,它会引发如下错误:
java.lang.NoClassDefFoundError
at org.apache.log4j.Logger.getLogger(Logger.java:118)
..
java.lang.NoClassDefFoundError: com.bgc.ordering.wizard.back.services.EswTestCase
尽管如此,我在类路径元素中将这些 jar 文件和类文件指定为:
和记录器 jar
<path id="CLASSPATH_JUNIT">
<fileset dir="${BUILD_LIBS_HOME}">
<include name="*.jar" />
</fileset>
<pathelement location="${TEST_CLASSES_DIR}" />
<pathelement location="${TEST_BUILD_DIR}" />
<pathelement location="${COMP_BUILD}" />
<pathelement location="${COMP_CLASSES}" />
<path location="${APP_DIR}\bgc-esw-services\target\classes"/>
<pathelement location="${APP_DIR}\bgc-esw-web\target\classes" />
...
log4j.properties 存在于${TEST_BUILD_DIR}
使用:apache-ant-1.8.1 和 junit-3.8.1.jar
【问题讨论】: