Ant Junit ClassNotFoundException...again



我知道他们有很多,但我只是没有看到解决方案,我们将非常感谢所有的帮助。因此,尝试制作一个ant任务来运行我的junit测试。运行到ClassNotFoundException。

<property name="testsrc" value="${project.home}/../extensions/myaddon/testsrc"/>
<property name="src" value="${project.home}/../extensions/myaddon/src"/>
<property name="websrc" value="${project.home}/../extension/myaddon/acceleratoraddon/web/src"/>
<property name="junitLocation" value="${project.home}/../lib/junit-4.10.jar"/>
<path id="test-path">
    <pathelement location="${testsrc}"/>
    <pathelement location="${src}"/>
    <pathelement location="${websrc}"/>
    <pathelement location="${junitLocation}"/>
</path>
<!--
Batch testing
This will be used to test every test file we have rather than having to specify individual ones
-->
<target name="codtests" description="run all junit tests for myaddon">
    <junit printsummary="yes" haltonfailure="no" showoutput="yes">
        <classpath>
            <path refid="test-path"/>
        </classpath>
        <batchtest>
            <fileset dir="${testsrc}">
                <include name="**/*Test.java" />
            </fileset>
        </batchtest>
    </junit>
    <echo message="batch testing done"/>
</target>

Stacktrace:

C:temcnacc.cod>ant codtests
Buildfile: C:temcnacc.codbuild.xml
codtests:
    [junit] Running codaddon.setup.CodSetupTest
    [junit] Testsuite: codaddon.setup.CodSetupTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit]
    [junit]     Caused an ERROR
    [junit] codaddon.setup.CodSetupTest
    [junit] java.lang.ClassNotFoundException: codaddon.setup.CodSetupTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:270)
    [junit]
    [junit] Test codaddon.setup.CodSetupTest FAILED
    [junit] Running codaddon.setup.FakeTest
    [junit] Testsuite: codaddon.setup.FakeTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit]
    [junit]     Caused an ERROR
    [junit] codaddon.setup.FakeTest
    [junit] java.lang.ClassNotFoundException: codaddon.setup.FakeTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:270)
    [junit]
    [junit] Test codaddon.setup.FakeTest FAILED
    [junit] Running codaddon.test.AutoPassTest
    [junit] Testsuite: codaddon.test.AutoPassTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit]
    [junit]     Caused an ERROR
    [junit] codaddon.test.AutoPassTest
    [junit] java.lang.ClassNotFoundException: codaddon.test.AutoPassTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:270)
    [junit]
    [junit] Test codaddon.test.AutoPassTest FAILED
    [junit] Running codaddon.test.Fake2Test
    [junit] Testsuite: codaddon.test.Fake2Test
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 se
c
    [junit]
    [junit]     Caused an ERROR
    [junit] codaddon.test.Fake2Test
    [junit] java.lang.ClassNotFoundException: codaddon.test.Fake2Test
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:270)
    [junit]
    [junit] Test codaddon.test.Fake2Test FAILED
     [echo] batch testing done
BUILD SUCCESSFUL
Total time: 0 seconds
C:temcnacc.cod>

您需要指向测试.class文件,而不是源文件
编译测试并将文件夹添加到测试路径

是的,您应该粘贴堆栈。也许只是胡乱猜测,您在哪里定义了${project.home}变量?我看到这是类路径中唯一一个可能没有解析的变量。

相关内容

  • 没有找到相关文章

最新更新