2011-01-22 4 views
16

junit 테스트를 실행할 수있는 build.xml이 있습니다.Ant 클래스 경로 및 junit.jar

<pathelement location="${eclipse.home}/plugins/org.junit4_4.5.0.v20090824/junit.jar"/> 

변화가 클래스 경로를 나누기로

<pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/> 

: 나는 라인을 교체 할 경우

<path id="JUnit 4.libraryclasspath"> 
    <pathelement location="../../../../../eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/> 
    <pathelement location="../../../../../eclipse/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/> 
</path> 
<path id="MyProject.classpath"> 
    <pathelement location="bin"/> 
    <path refid="JUnit 4.libraryclasspath"/> 
</path> 

<target name="run_unit_tests" depends="build"> 
     <mkdir dir="${junit.output.dir}"/> 
     <junit printsummary="yes" haltonfailure="no"> 
      <classpath refid="MyProject.classpath" /> 

      <formatter type="xml"/> 
      <batchtest todir="${junit.output.dir}"> 
        <fileset dir="${src}"> 
          <include name="**/*Test*.java"/> 
        </fileset> 
      </batchtest> 
     </junit> 
</target> 

다음은 관련 부분이다. 다음과 같은 오류가 발생합니다 :

The <classpath> for <junit> must include junit.jar if not in Ant's own classpath

내가 이해하는 한, 위치 속성은 두 경우 모두 동일한 값을 유지해야합니다. 그렇다면 그 이유는 무엇일까요?

이 빌드 파일은 다른 junit 버전 (경로가 끊어짐)이있는 환경에서는 작동하지 않습니다. junit.jar에 "일반"경로를 추가 할 수 있습니까?

+0

eclipse.home은 제대로 확장 되었습니까? –

답변

24

JUnit 라이브러리는 사용자가 상주하도록 말할 때마다 상주합니다. 개인적으로 Eclipse와 함께 제공되는 jar 파일과 연결하는 것에 대해서는 완전히 잊어 버리고 대신 download the jars directly을 잊어 버릴 것입니다.

프로젝트가있는 경우 /project 경로에 말하면 /project/test/lib/junit.jar과 같이 해당 계층 구조의 종속성을 지정하려고합니다. 내 ant 빌드 파일이 /project/build.xml 인 경우 JUnit 클래스 경로에 ./test/lib/junit.jar을 추가하는 것만 큼 간단합니다. (프로젝트의 내용도 어디서나저장 될 수 있기 때문에) 상대 경로를 사용하여 특히 컴퓨터에 임의의 위치를 ​​참조하려고하면, (기억, 이클립스 어디을 설치할 수) 깨지기 쉬운 것입니다.

4

Linux를 사용하는 경우 항아리를 다른 위치로 심볼릭 링크 할 수 있습니다. 이렇게하면 버전을 포함하지 않는 경로로 심볼릭 링크 할 수 있습니다. 예 :

ln -s plugins/org.junit4_4.5.0.v20090824/junit.jar /wherever/junit.jar 

eclipse 서브 디렉토리 외부에 라이브러리 폴더가 있어야 할 수도 있습니다. 의존성을 관리하기 위해 ivy 또는 maven을 사용할 수도 있습니다.

위의 예제가 실패하는 이유는 모르겠지만 오류 메시지는 junit.jar을 찾을 수 없다는 것을 의미합니다. eclipse.home이 설정되어 있습니까?

<echo message="${eclipse.home}"> 
+0

+1은 $ {eclipse.home}입니다. 이제 libs를 프로젝트에 하드 코딩하거나 복사하는 대신 Eclipse 플러그인에 상대적으로 링크되는 build.xml 스크립트를 작성할 수 있습니다. – jmort253