简体   繁体   中英

Ant Junit ClassNotFoundException…again

I'm aware they're are plenty of these but I just am not seeing the solution and all help would be very much appreciated. So trying to make an ant task to run my junit tests. Running into the 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:\tem\cnacc.cod>ant codtests
Buildfile: C:\tem\cnacc.cod\build.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:\tem\cnacc.cod>

Yes, you should be pasting the stacktrace. Perhaps as a wild guess, where have you defined the ${project.home} variable ? I see this is the only variable in the classpath which might not have resolved.

You need to point to test .class files, not sources.
Compile your tests and add the folder to the test-path .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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