Junit Classpath в муравей - PullRequest
       307

Junit Classpath в муравей

0 голосов
/ 27 марта 2012

У меня возникают проблемы при попытке использовать

<dirsets>

в моем муравейнике. Это фрагмент пути к классам.

<target name="myTests" >     
    <junit haltonerror="true" haltonfailure="true" fork="true">
        <classpath>
            <dirset dir="/my/absolute/root/path/where/I/keep/compiled/classes">
                <include name="com/mycompany/mytests"/>
                </dirset>
                <pathelement location="my/path/to/jars/myjar1.jar" />  
                <pathelement location="my/path/to/jars/myjar2.jar" />  
                <!-- and so on -->  
             </classpath>
    <test name="com.mycompany.mytests.MyFirstTest" 
               outfile="${dir.report.test}/report_MyFirstTest">
                <formatter type="xml" />
</test> 
    </junit>
   </target> 

когда я запускаю тест, успешно скомпилировав весь код, ant жалуется:

java.lang.ClassNotFoundException: com.mycompany.mytests.MyFirstTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)

Я пытался с абсолютными, относительными путями, и это никогда не работает. Мой путь к классам состоит из множества jar-файлов, указанных для многих и тех, которые никогда не распознаются Где моя вина?

спасибо

1 Ответ

1 голос
/ 27 марта 2012

В прежние времена, когда я использовал ant, я использовал вложенный элемент <classpath> и указывал путь к классу со структурой path-like - вот так:

<path id="project.test.classpath">
    <pathelement location="/my/absolute/root/path/where/I/keep/compiled/classes" />
    <fileset dir="/my/path/to/jars">
        <include name="**/*.jar" />
    </fileset>
</path>


<target name="myTests">
    <junit haltonerror="true" haltonfailure="true" fork="true">
        <classpath refid="project.test.classpath" />
        <test name="com.mycompany.mytests.MyFirstTest" outfile="${dir.report.test}/report_MyFirstTest">
            <formatter type="xml" />
        </test>
    </junit>
</target> 

Может быть, это подходит и для вас.

...