Danny Gloudemans
Danny Gloudemans

Reputation: 2677

Generate XML reports with Ant, but how to?

At the moment I want to get the test results in Jenkins. The only problem I'm dealing with is that I can get the XML reports from my Junit Tests. So my question is:

  1. Is there a possibility to start the tests with Jenkins and get the results?

  2. Or is it possible to generate the xml reports with Ant, and how? Because I had this but don't understand it 100%:

Path to my tests:

Path to my libraries:

This code I get from the JUnit site: http://junit.sourceforge.net/doc/faq/faq.htm#running_6


I understand the following: ${test.reports} = Location where you want your test reports ${classes} = The bin directory where the .java files are already build into .class files. Is it also possible to forward them to the .java files?

But I don't know what to do with the following:

<classpath refid="test.classpath" />

Thanks already!

Update

He found my 3 testclasses and he build a report, but I get the same error in this three classes in the report:

test.AllTests

java.lang.ClassNotFoundException: test.AllTests
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)

This is my build.xml code:

<property name="basedir" value="C:/CMSdot2"/>
<property name="classes" value="C:/CMSdot2/dotCMS/WEB-INF/classes/nl/company/dotcms/plugin"/>
<property name="test.reports" value="${basedir}/dotCMS/"/>
<target name="test-html">
 <junit fork="yes" printsummary="no" haltonfailure="no">
  <batchtest fork="yes" todir="${test.reports}" >
   <fileset dir="${classes}">
    <include name="**/*Test*.class" />
   </fileset>
  </batchtest>
  <formatter type="xml" />
  <classpath id="test.classpath">
   <pathelement location="lib/junit-4.10.jar"/>
  </classpath>
 </junit>
 <junitreport todir="${test.reports}">
  <fileset dir="${test.reports}">
   <include name="TEST-*.xml" />
  </fileset>
  <report todir="${test.reports}" />
 </junitreport>
</target>

Upvotes: 1

Views: 2019

Answers (1)

oers
oers

Reputation: 18714

  1. You have to specify ${classes} to point to the classes. Java needs classes to execute programs/junit so .java file won't do.
  2. You need <classpath refid="test.classpath" /> to include your classes and any eyternal lib if you have external libs (like log4j, or apache commons) that are needed to run your tests. For example:

    <classpath id="test.classpath">
        <pathelement location="${classes}" />
        <pathelement location="lib/ther.jar"/>
    </classpath>
    

Upvotes: 1

Related Questions