지금 있는 프로젝트에서 테스트 코드 관련 이슈가 하나 생겼습니다.
그런데 밑에 있는 친구가 아주 좋은 방법을 찾아서 소개합니다.
<target name="test" description="Runs JUnit tests">
<junit printsummary="yes" haltonfailure="no" fork="true" forkmode="once" failureproperty="test.failed" errorproperty="test.failed">
<classpath refid="test.classpath" />
<batchtest fork="true" todir="${test.report}">
<fileset dir="${test.src}">
<include name="**/*TestCase.java" />
</fileset>
<formatter type="xml" />
</batchtest>
</junit>
</target>
테스트 코드를 실행하는데 너무 많은 시간이 걸린다.이슈를 분석해 보니 원인이 크게 두가지로 나왔습니다.
- 테스트 코드마다 스프링 컨텍스트 파일을 로딩하도록 해놔서 시간을 잡아먹는다.
- 커버리지를 측정하기 위해 기록하는데 시간이 오래걸린다.
그런데 밑에 있는 친구가 아주 좋은 방법을 찾아서 소개합니다.
Ant에서 JUnit을 실행할 때 사용하는 junit 타겟에 forkmode="once"를 주게 되면 테스트코드를 실행할때 매번 새로운 VM을 만들지 않고 하나의 VM만을 사용합니다.
<target name="test" description="Runs JUnit tests">
<junit printsummary="yes" haltonfailure="no" fork="true" forkmode="once" failureproperty="test.failed" errorproperty="test.failed">
<classpath refid="test.classpath" />
<batchtest fork="true" todir="${test.report}">
<fileset dir="${test.src}">
<include name="**/*TestCase.java" />
</fileset>
<formatter type="xml" />
</batchtest>
</junit>
</target>
- fork="true" forkmode="Once" : JVM이 두개 생성됩니다. Ant를 위한 VM, JUnit을 위한 VM
- fork="false" : JVM은 한개 생성됩니다. Ant와 JUnit을 위한 VM
'Work & Study > TechTalk' 카테고리의 다른 글
| Pragmatic Magazine에 실린 Responsive Design (0) | 2009/09/19 |
|---|---|
| InfoQ Agile 2009 특집 (0) | 2009/09/18 |
| JUnit 테스트코드를 단일 클래스 로더에서 실행하는 방법 (0) | 2009/09/10 |
| Agile 2009 Conference 참관기 - 1일, Priorizing Your Product Backlog (0) | 2009/09/01 |
| Agile 2009 Conference 참관기 - 1일 (0) | 2009/09/01 |
| Agile 2009 Conference 참관기 - 0일 (2) | 2009/08/28 |


