2015-01-30 2 views
1

I가 내가 ./lib에서의 JUnit-4.7.jar에 놓여있다개미와 주석이 JUnit 테스트

public class CardTest { 
    @Test 
    public void testCardCompareWithSameValue() throws Exception { 
     Card card1 = new Card(Card.COLOR.CLUBS, 4); 
     Card card2 = new Card(Card.COLOR.SPADES, 4); 

     Card.MATCH_TYPE match = card1.compareCard(card2); 

     assertEquals("The returned match must be of enum type Card.MATCH_TYPE.VALUE", 
      Card.MATCH_TYPE.VALUE, match); 
    } 
} 

./src/com.example.package.tests에서 다음 테스트 클래스

및 다음을가집니다. /build.xml

<project name="Project" basedir="." default="main"> 

    <property name="src.dir" value="src" /> 
    <property name="build.dir" value="build" /> 
    <property name="classes.dir" value="${build.dir}/classes" /> 
    <property name="jar.dir" value="${build.dir}/jar" /> 
    <property name="lib.dir" value="lib" /> 
    <property name="main-class" value="com.example.package.gui.Main" /> 
    <property name="report.dir" value="${build.dir}/junitreport" /> 

    <path id="classpath"> 
     <fileset dir="${lib.dir}" includes="**/*.jar" /> 
    </path> 


    <path id="application" location="${jar.dir}/${ant.project.name}.jar"/> 


    <target name="clean"> 
     <delete dir="${build.dir}" /> 
    </target> 

    <target name="compile"> 
     <mkdir dir="${classes.dir}" /> 
     <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" /> 
     <copy todir="${classes.dir}"> 
      <fileset dir="${src.dir}" excludes="**/*.java" /> 
     </copy> 
    </target> 

    <target name="jar" depends="junit"> 
     <mkdir dir="${jar.dir}" /> 
     <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" excludes="**/*Test.class"> 
      <manifest> 
       <attribute name="Main-Class" value="${main-class}" /> 
      </manifest> 
     </jar> 

    </target> 


    <target name="junit" depends="compile"> 
     <mkdir dir="${report.dir}" /> 
     <junit printsummary="yes" haltonfailure="yes" showoutput="yes"> 
      <classpath> 
       <path refid="classpath" /> 
       <path location="${classes.dir}" /> 
       <path refid="application" /> 
      </classpath> 

      <formatter type="xml" /> 

      <batchtest fork="yes"> 
       <fileset dir="${src.dir}" includes="*Test.java" /> 
      </batchtest> 
     </junit> 
    </target> 

    <target name="junitreport" depends="junit"> 
     <junitreport todir="${report.dir}"> 
      <fileset dir="${report.dir}" includes="TEST-*.xml" /> 
      <report todir="${report.dir}" /> 
     </junitreport> 
    </target> 


    <target name="run" depends="jar"> 
     <java classname="${main-class}" fork="true" > 
      <classpath> 
       <path refid="classpath" /> 
       <path refid="application" /> 
      </classpath> 
     </java> 
    </target> 

    <target name="clean-build" depends="clean,jar" /> 

    <target name="main" depends="clean,run" /> 

</project> 

개미가 내 junit 테스트를 실행하지 않는 이유는 무엇입니까? 보고서를 확인할 때 0 개의 테스트가 있다고합니다.

OS X Yosemite를 사용하고 있고 이진 다운로드를 통해 Ant를 설치했습니다.

편집 : 우분투 테스트도 변경되지 않았습니다.

답변

0

.

 <batchtest fork="yes" skipnontests="yes" todir="${report.dir}"> 
      <fileset dir="${classes.dir}" /> 
     </batchtest> 
+1

'todir' att를 넣지 마십시오. libute라면'build.xml' 파일이 들어있는 디렉토리에 보고서를 작성해야합니다. 거기에서 봤어? 이 방법이 효과가 있다면 기쁘게 생각합니다. –

+0

예, 테스트를 발견 한 내용은 includes = ""속성을 제거한 것입니다. – Tebro

1

Ant JUnit Task documentation에 따르면 todir 속성을 사용하여 테스트 보고서를 넣을 곳을 batchtest에게 알려야합니다. 그렇지 않으면 현재 작업 디렉토리에 기록합니다.

<batchtest fork="yes" todir="${report.dir}"> 
      <fileset dir="${src.dir}" includes="*Test.java" /> 
     </batchtest> 

작동해야합니다. 당신이 <junit>을 실행하면

+0

TESTS-TestSuits.xml을 빌드/junitreport로 출력합니다. 여기서 올바른 것으로 생각됩니다. – Tebro

3

하면, 당신은 컴파일 테스트 클래스 파일 아닌를 참조 할 * xml 파일 -.

또한 테스트의 무리가 있는지 확인하기 위해 현재 작업 디렉토리를 확인 테스트 Java 소스 파일.

정규 소스와 테스트 소스를 두 개의 다른 디렉토리에 넣은 다음 두 개의 다른 디렉토리로 컴파일하는 것이 좋습니다. 우리는 Maven 디렉토리 표준을 사용합니다 :

  • src/main/java - 정규 소스 파일의 위치.
  • src/main/resources - 리소스의 위치 (병에 들어가는 XML 및 JSON 파일).
  • src/test/java - 테스트 소스 파일의 위치.
  • src/test/resources - 테스트에 필요한 리소스의 위치.
  • target/classes - 정규 소스 클래스 파일을 컴파일하는 곳입니다.
  • target/test-classes - 테스트 클래스 파일이 컴파일되는 곳입니다.

예 :이, @ DAWID-w 's 및 @dkatzel의 답변의 조합을 일을 무엇 이었습니까

<target name="compile"> 
    <javac srcdir="src/main/java" 
     destdir="target/classes"> 
     <classpath ref="main.classpath"/> 
    </javac> 
</target> 

<target name="package" 
    depends="compile"> 
    <jar destfile="target/${ant.project.name}.jar"> 
     <fileset dir="target/classes"/> 
     <fileset dir="src/main/resources"/> 
    </jar> 
</target> 

<target name="compile-test" 
    depends="compile"> 

    <!-- Classpath must include the main.classpath from --> 
    <!-- above, the test.classpath which will include --> 
    <!-- "junit.jar", and finally the compiled classes --> 
    <!-- from target/classes. Not 100% sure if this is --> 
    <!-- the correct way to specify it, but it's close. --> 
    <javac srcdir="src/test/java" 
     destdir="target/test-classes"> 
     <classpath> 
      <path ref="main.classpath"/> 
      <path ref="test.classpath"/> 
      <path location="target/classes"/> 
     <classpath> 
    </javac> 
</target> 

<junit printsummary="yes" 
    haltonfailure="yes" 
    showoutput="yes"> 
    <classpath> 
     <path refid="main.classpath" /> 
     <path refid="test.classpath" /> 
     <path location="${classes.dir}" /> 
    </classpath> 

     <!-- Batchtest is pointing to the classes--> 
     <formatter type="xml" /> 
     <batchtest fork="yes"> 
      <fileset dir="${target/test-classes}"/> 
     </batchtest> 
    </junit> 
</target> 
+0

을 클래스를 가리 키도록 변경했지만 여전히 작동하지 않습니다. 프로젝트 구조에 대한 제안에 감사드립니다.하지만 변환하려고 시도했을 때 많은 것들이 엉망이되어 현재 현재의 상태로 유지할 것입니다. – Tebro

+1

"ant -d와 함께 실행하면 더 많은 것을 인쇄 할 수 있으므로 파일에 저장하거나 깨끗한 터미널과 큰 터미널 버퍼로 시작해야합니다. 'batchtest' 라인이 실제로 실행되는지 또는'junit' 태스크가 실행 중인지 그리고 무슨 일이 일어나는지 확인하십시오. –

+0

이것은 junit 파트의 결과입니다 : [pastebin] (http://pastebin.com/qcCVwev1) – Tebro

관련 문제