Проблемы с Ant + Junit - PullRequest
       8

Проблемы с Ant + Junit

0 голосов
/ 22 января 2012

Я пытаюсь заставить Джунит работать с Ант. Я сталкивался с вопросами по теме. Я предполагаю, что где-то есть небольшая ошибка, но я не могу понять это. Вот мой файл сборки:

        <?xml version="1.0" encoding="UTF-8"?>
    <project name="IvleFileSync" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
      <!-- set global properties for this build -->
      <property name="src" location="src"/>
      <property name="build" location="build"/>
      <property name="dist"  location="dist"/>
        <!-- Variables used for JUnit testing -->
        <property name="test.dir" location="test" />
        <property name="test.report.dir" location="test-reports" />
     <path id="junit-classpath">
    <fileset dir="${test.dir}">
        <include name = "*" />
    </fileset>
     </path>

    <path id="files-classpath">
    <fileset dir="/usr/lib" >
        <include name="*.jar"/>
    </fileset>
    </path> 

      <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
    <mkdir dir="${test.report.dir}" />
      </target>

      <target name="compile" depends="init" description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
     <javac srcdir="${src}" destdir="${build}"> 
           <classpath>
        <path refid="files-classpath" />
    </classpath> 
    </javac>

       </target>

      <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/IvleFileSync-${DSTAMP}.jar" basedir="${build}"/>
      </target>

    <target name="compile-test" depends="compile" description="compile the tests " >
       <!-- Compile the java code from ${src} into ${build} -->
       <javac srcdir="${test.dir}" destdir="${build}"> 
         <classpath>
          <path refid="files-classpath" />
       </classpath> 
       </javac>

    </target>

    <target name="test" depends="compile-test" description="Execute Unit Tests" >
      <junit printsummary="yes" fork="yes" haltonfailure="yes" showoutput="false">
       <classpath >
    <path refid="files-classpath" />
    <path refid= "junit-classpath" />
       </classpath>
    <batchtest fork="yes" todir="${test.report.dir}/"> 
            <formatter type="xml"/> 
            <fileset dir="${test.dir}"> 
                <include name="*Test*.java"/> 
            </fileset> 
    </batchtest> 
      </junit>
    </target>

      <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${test.report.dir}" />
    <delete dir="${dist}"/>
      </target>
    </project>

И у меня есть тестовые файлы в каталоге / test, а также я поместил фляги в ANT_HOME / lib

Это не работает, и я получаю эту ошибку, когда выкапываю результаты теста / .... xml

<error message="NewEmptyJUnitTest"     type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: NewEmptyJUnitTest
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)

Спасибо, что помогли мне ...

Ответы [ 2 ]

2 голосов
/ 22 января 2012

Путь к классу для задачи junit не включает выходные данные цели теста компиляции.Используйте что-то вроде следующего для classpath JUnit:

<classpath>
  <pathelement path="${build}"/>
  <path refid="files-classpath" />
  <path refid="junit-classpath" />
</classpath>
1 голос
/ 22 января 2012

Вы забыли добавить свои собственные классы ("build") к цели "test".

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...