이전 포스트에 이어집니다.

junit task를 다음과 같이 변경할 수 있습니다.
    <target name="test" depends="compile">
        <mkdir dir="report/html"/>
        <junit printsummary="on" haltonfailure="on">
            <classpath refid="test.classpath">
            </classpath>
            <formatter type="xml"/>
            <batchtest todir="report">
                <fileset dir="dst">
                    <include name="**/*Test*"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

리포팅 기능을 강화한 설정입니다.
report 폴더에 TEST-*.xml 파일이 생성이 됩니다.
이 파일을 이용해서 다음과 같은 문서를 생성할 수 있습니다.


추가되는  junitreport 코드는 다음과 같습니다. 굵게 표시해 놓았습니다.
    <target name="test" depends="compile">
        <mkdir dir="report/html"/>
        <junit printsummary="on" haltonfailure="on">
            <classpath refid="test.classpath">
            </classpath>
            <formatter type="xml"/>
            <batchtest todir="report">
                <fileset dir="dst">
                    <include name="**/*Test*"/>
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="report">
            <fileset dir="report">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="report/html"/>
        </junitreport>
    </target>

이제 남은 작업은 소스와 테스트코드 분리 설정과 그 후에 okjsp사이트에 적용하는 것입니다.
샘플 첨부합니다.

참고서적: 이클립스 프로젝트 필수 유틸리티, 민진우, 이인선 , 한빛미디어, 2009, p251~255
생각보다 쉽게 풀리지 않습니다. 테스트 코드와 애플리케이션 코드의 분리는 아직 적용하기 전입니다. classpath를 두 가지로 놓아 둔 것이 특징이라면 특징이겠죠. 멋지게 나오는 리포트까지 몇 번 더 진화를 시켜야하겠습니다.

<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
     2009. 6. 9. 오전 8:23:18
     junit   
     test case report
     kenu
====================================================================== -->
<project name="junit" default="compile">
    <description>
            test case report
    </description>
    <path id="classpath1">
        <fileset dir="lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    <path id="test.classpath">
        <fileset dir="lib">
            <include name="**/*.jar"/>
        </fileset>
        <path location="dst"></path>
    </path>

    <!-- =================================
          target: default             
         ================================= -->
    <target name="compile" description="test case report">
        <mkdir dir="dst"/>
        <javac srcdir="src" destdir="dst" debug="on">
            <classpath refid="classpath1">
            </classpath>
        </javac>
    </target>

    <!-- - - - - - - - - - - - - - - - - -
          target: depends                     
         - - - - - - - - - - - - - - - - - -->
    <target name="test" depends="compile">
        <junit>
            <classpath refid="test.classpath">
            </classpath>
            <test name="test.UnitTest"></test>
        </junit>
    </target>

</project>


이클립스 프로젝트 파일 첨부합니다.

지난 글에서도 언급했지만 JUnit은 소프트웨어 업계의 잘 나가는 두 분이 만들었다고 했습니다. Kent Beck, 그리고 Erich Gamma 이 두 분이죠. 한 분은 TDD, Agile, XP로 다른 한 분은 디자인 패턴, 이클립스로 잘 살고 계시죠.

Registered : 2000-11-24 16:05 
뜬금 없는 이 날짜는 sourceforge.net에 JUnit프로젝트가 등록된 날입니다.
http://sourceforge.net/projects/junit/
링크된 페이지 우측 하단에서 확인할 수 있습니다.

8년 전 내가 만든 소프트웨어가 아직도 발전되고 쓰이고 있다면 기분이 어떨까요. 제 생각으로는 비슷한 것 중에 ANT가 있다고 생각됩니다.

JUnit 4.4가 현재 버전입니다. 3.8.x 까지의 컨벤션들이 Javadoc스타일의 Annotation 때문에 모두 바뀌었습니다.

  1. TestCase를 상속받지 않아도 되고요.
  2. 메소드명이 test로 시작하지 않아도 됩니다.

그 외에도 많은 특징들이 있지만 일단 샘플 하나를 소개하고 마칠까 합니다.

package test;

import org.junit.Test;

import junit.framework.Assert;

public class UnitTest {
 @Test
 public void 더하기() {
  Assert.assertEquals(2, add(1,1));
 }

 private Object add(int i, int j) {
  return i + j;
 }
}

+ Recent posts