Java Ant JUnit抛出ClassNotFoundException

Java Ant JUnit抛出ClassNotFoundException,java,junit,ant,travis-ci,Java,Junit,Ant,Travis Ci,我正在IntellijIDE中开发一个Java应用程序。为了能够将我的repo连接到Travis CI,我使用IDE生成了ant build.xml。但是IntelliJ尚未在生成文件中创建测试目标。我已通过添加以下内容对其进行手动编辑: <target name="test" depends="compile.module.pearplanner.tests"> <junit> <classpath> <

我正在IntellijIDE中开发一个Java应用程序。为了能够将我的repo连接到Travis CI,我使用IDE生成了ant build.xml。但是IntelliJ尚未在生成文件中创建测试目标。我已通过添加以下内容对其进行手动编辑:

<target name="test" depends="compile.module.pearplanner.tests">
    <junit>
        <classpath>
            <pathelement location="lib/junit-4.12.jar"/>
        </classpath>
        <batchtest>
            <fileset dir="./Test/">
                <include name="**/*Test*" />
            </fileset>
        </batchtest>
        <formatter type="brief" usefile="false"/>
    </junit>
</target>
我收到以下错误:

test:
[junit] Testsuite: Model.AccountTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit] 
[junit] Null Test:  Caused an ERROR
[junit] Model.AccountTest
[junit] java.lang.ClassNotFoundException: Model.AccountTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:348)
[junit] 
[junit] 
[junit] Test Model.AccountTest FAILED
[junit] Testsuite: Model.PersonTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit] 
[junit] Null Test:  Caused an ERROR
[junit] Model.PersonTest
[junit] java.lang.ClassNotFoundException: Model.PersonTest
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:348)
[junit] 
[junit] 
[junit] Test Model.PersonTest FAILED
BUILD SUCCESSFUL
Total time: 0 seconds


我已经测试了我在网络上可以找到的多种方法,但它们都给了我相同的结果。我做错了什么?

我设法解决了它。事实证明,我必须在类路径中指定类输出目录和测试类输出目录。此外,hamcrest-core-1.3.jar也不存在。正确版本:

<target name="test" depends="build.modules" >
    <junit haltonerror="yes" haltonfailure="yes">
        <classpath>
            <pathelement location="${basedir}/lib/junit-4.12.jar"/>
            <pathelement location="${basedir}/lib/hamcrest-core-1.3.jar"/>
            <pathelement location="${pearplanner.output.dir}/"/>
            <pathelement location="${pearplanner.testoutput.dir}/"/>
        </classpath>
        <batchtest>
            <fileset dir="${pearplanner.testoutput.dir}">
                <include name="**/*Test*" />
            </fileset>
        </batchtest>
        <formatter type="brief" usefile="false"/>
    </junit>
</target>

需要测试的类在哪里?将其添加到类路径中。
<target name="test" depends="build.modules" >
    <junit haltonerror="yes" haltonfailure="yes">
        <classpath>
            <pathelement location="${basedir}/lib/junit-4.12.jar"/>
            <pathelement location="${basedir}/lib/hamcrest-core-1.3.jar"/>
            <pathelement location="${pearplanner.output.dir}/"/>
            <pathelement location="${pearplanner.testoutput.dir}/"/>
        </classpath>
        <batchtest>
            <fileset dir="${pearplanner.testoutput.dir}">
                <include name="**/*Test*" />
            </fileset>
        </batchtest>
        <formatter type="brief" usefile="false"/>
    </junit>
</target>