2016-04-19 2 views
0

Я продолжаю получать эти ошибки, когда пытаюсь запустить файл ant.Ошибка: пакет org.junit не существует

[javac] Compiling 8 source files to C:\Users\FaradaysCage\git\mancala\build 
    [javac] C:\Users\FaradaysCage\git\mancala\src\tests\BoardDataTest.java:1: error: package org.junit does not exist 
    [javac] import static org.junit.Assert.assertEquals; 
    [javac]      ^
    [javac] C:\Users\FaradaysCage\git\mancala\src\tests\BoardDataTest.java:1: error: static import only from classes and interfaces 
    [javac] import static org.junit.Assert.assertEquals; 
    [javac]^
    [javac] C:\Users\FaradaysCage\git\mancala\src\tests\BoardDataTest.java:2: error: package org.junit does not exist 
    [javac] import org.junit.Test; 
    [javac]    ^
    [javac] C:\Users\FaradaysCage\git\mancala\src\tests\BoardDataTest.java:8: error: cannot find symbol 
    [javac]  @Test 

Это мой муравей файл сборка

<project name="Mancala" default="fullBuild" basedir="."> 
    <description> 
    Build file for Mancala program. Currently handles compilation 
    and distribution. Will also include automated testing and 
    generation of documentation. 
    </description> 
    <!-- set global properties for this build --> 
    <property name="src" location="src" /> 
    <property name="build" location="build" /> 
    <property name="build.test" location="build/tests" /> 
    <property name="dist" location="dist" /> 
    <property name="test" location="src/tests" /> 
    <property name="docs" location="docs" /> 
    <property name="test.report" location="testreport" /> 

    <!-- Define the classpath which includes the junit.jar--> 
    <!-- and the classes after compiling--> 
    <path id="junit.class.path"> 
     <pathelement location="lib/junit-4.11.jar" /> 
     <pathelement location="lib/hamcrest-core-1.3.jar" /> 
     <pathelement location="${build}" /> 
    </path> 

    <target name="init"> 
     <!-- Create the time stamp --> 
     <tstamp /> 
     <!-- Create the build directory structure used by compile --> 
     <mkdir dir="${build}" /> 
     <!-- Create the testreport directory used by Junit --> 
     <mkdir dir="${test.report}" /> 
     <!-- Create the build.test directory used by compile & Junit --> 
     <mkdir dir="${build.test}" /> 
    </target> 

    <target name="compile" depends="init" description="compile the source"> 
     <!-- Compile the java code from ${src} into ${build} --> 
     <javac srcdir="${src}" destdir="${build}" /> 
     <javac srcdir="${test}" destdir="${build.test}" /> 
    </target> 

    <!-- Run the JUnit Tests --> 
    <!-- Output is XML, could also be plain--> 
    <target name="junit" depends="compile"> 
     <junit printsummary="on" fork="true" haltonfailure="yes"> 
      <classpath> 
       <classpath refid="junit.class.path" /> 
       <pathelement location="${build.test}" /> 
       <formatter type="plain" /> 
       <batchtest todir="${test.report}"> 
        <fileset dir="${test}"> 
         <include name="**/*Test*.java" /> 
        </fileset> 
       </batchtest> 
      </classpath> 
     </junit> 
    </target> 

    <target name="doc" description="generate documentation"> 
     <mkdir dir="${docs}" /> 
     <javadoc sourcepath="${src}" destdir="${docs}"> 
      <fileset dir="${src}" /> 
     </javadoc> 
    </target> 

    <target name="dist" depends="compile" description="generate the distribution"> 
     <!-- Create the distribution directory --> 
     <mkdir dir="${dist}/lib" /> 

     <!-- Put everything in ${build} into the Mancala-${DSTAMP}.jar file --> 
     <jar jarfile="${dist}/lib/Mancala-${DSTAMP}.jar" basedir="${build}" /> 
    </target> 

    <!-- Runs the compiled application --> 
    <target name="run" depends="compile"> 
     <java classname="MancalaApp"> 
      <classpath> 
       <pathelement location="${build}" /> 
      </classpath> 
     </java> 
    </target> 

    <!--Add unit tests to build once implemented--> 
    <target name="fullBuild" depends="dist, doc, junit" description="create application, docs, and tests"> 
    </target> 

    <target name="clean" description="clean up"> 
     <!-- Delete the ${build} and ${dist} directory trees --> 
     <delete dir="${build}" /> 
     <delete dir="${dist}" /> 
     <delete dir="${docs}" /> 
     <delete dir="${build.test}" /> 
     <delete dir="${test.report}" /> 
    </target> 
</project> 

Я знаю, что-то я не включая junit.jar в мои сборки, но это должно быть быть включено из-за в моем пути ид, и я я в конце концов о том, что не так.

Спасибо заранее

+0

Проверьте эту статью о подготовке скрипта сборки ant [ant build script] (http://ant.apache.org/manual/using.html#path). Я хотел бы попробовать что-то, как следует ' <набор файлов реж = "Lib"> <включают имя = "**/*. Банку"/> ' – MSameer

+1

* Я не включаю junit.jar в свою сборку, но она должна быть включена из-за моего пути id *: нет, это не должно. Как вы думаете, почему? Вы видели где-то в документации, что если путь определен с идентификатором, он автоматически добавляется в путь к классам задачи javac? Это не. –

ответ

0

<javac> The задачи, которая создает тесты нужен: путь к классам

<javac srcdir="${test}" destdir="${build.test}" classpathref="junit.class.path" /> 

Кстати, следующий не выглядит правильно:

<junit printsummary="on" fork="true" haltonfailure="yes"> 
    <classpath> 
     <classpath refid="junit.class.path" /> 
     <pathelement location="${build.test}" /> 
     <formatter type="plain" /> 
     <batchtest todir="${test.report}"> 
      <fileset dir="${test}"> 
       <include name="**/*Test*.java" /> 
      </fileset> 
     </batchtest> 
    </classpath> 
</junit> 

<formatter> и <batchtest> элементы не должны вставляться под <classpath>. Они должны быть непосредственно под <junit>. Это должно быть больше похоже:

<junit printsummary="on" fork="true" haltonfailure="yes"> 
    <classpath> 
     <classpath refid="junit.class.path" /> 
     <pathelement location="${build.test}" /> 
    </classpath> 
    <formatter type="plain" /> 
    <batchtest todir="${test.report}"> 
     <fileset dir="${test}"> 
      <include name="**/*Test*.java" /> 
     </fileset> 
    </batchtest> 
</junit> 
Смежные вопросы