<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>
Caught an exception while logging the end of the build. Exception was:
java.lang.OutOfMemoryError: PermGen space
为什么要花很长时间才能生成XML?如何解决此错误并使应用程序快速运行.我最多只能有10个测试文件.我使用命令promt执行蚂蚁脚本.
分析:
1)如果我仅对扩展了Junit测试的测试进行批处理测试,则执行速度非常快.例如:
public class ImpactsParserTest extends
@H_404_28@
TestCase{..2)现在,如果我有将弹簧单元测试扩展为的测试类:
public class AddressLookupServiceTest
extends EswTestCase{..public class EswTestCase extends
@H_404_28@
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
即使,我已经在classpath元素中将这些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" />
…
$4.{TEST_BUILD_DIR}上的log4j.properties
使用:apache-ant-1.8.1和junit-3.8.1.jar
我的猜测是,您不仅要运行单元测试,还要运行集成测试,例如您有一个与Spring关联的类,并且需要它们的依赖关系.这就是为什么要使用EswTestCase.如果您只想编写单元测试,建议您实例化您的类,并模拟与您未直接测试的其他类的依赖关系.这将最大限度地减少内存占用,因为您不必创建Spring应用程序上下文.
这就是JavaDoc关于AbstractDependencyInjectionSpringContextTests的说法:
Really for integration testing,not
@H_404_28@
unit testing. You should not normally
use the Spring container for unit
tests: simply populate your POJOs in
plain JUnit tests!从Spring 3.0开始,旧版JUnit 3.8基类层次结构(即AbstractDependencyInjectionSpringContextTests,AbstractTransactionalDataSourceSpringContextTests等)已正式弃用,并将在以后的版本中删除.建议您使用Spring TestContext Framework编写集成测试.而不是使用AbstractDependencyInjectionSpringContextTests扩展EswTestCase,应使用注释.
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class EswTestCase { ... }