繁体   English   中英

蚂蚁JUnit抛出ClassNotFoundException

[英]Ant JUnit throws ClassNotFoundException

我正在IntelliJ IDE中开发Java应用程序。 为了能够将我的仓库连接到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>

当我跑步

ant test 

我收到以下错误:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM