JunitReport mit Ant

Status
Nicht offen für weitere Antworten.

pymote

Aktives Mitglied
Hallo,
ich versuche mich gerade bei der Durchführung von JunitTests per Ant und der Erstellung von Junit HTML Reports.
Ich benutze Eclipse 3.1.2, Ant 1.6.5 und Junit 3.8.1.
Mein Ant-Buildfile richtet sich nach folgenden Tutorials:
- ideoplex.com/id/25/ant-and-junit
- junit.sourceforge.net/doc/faq/faq.htm#running_6

Der Test läuft auch ohne Fehler ab. Allerdings werden keine Resultate gespeichert.

hier mal die Konsolen-Ausgabe:
Code:
Buildfile: c:\eclipse\workspace\TestProjekt\build.xml
compile-test:
    [javac] Compiling 1 source file
    [javac] [parsing started C:\eclipse\workspace\TestProjekt\TestExample.java]
    [javac] [parsing completed 31ms]
    [javac] [search path for source files: [C:\eclipse\workspace\TestProjekt]]
    [javac] [search path for class files: [C:\Java\jdk1.5.0_05\jre\lib\rt.jar, C:\Java\jdk1.5.0_05\jre\lib\jsse.jar,
 C:\Java\jdk1.5.0_05\jre\lib\jce.jar, C:\Java\jdk1.5.0_05\jre\lib\charsets.jar, 
C:\Java\jdk1.5.0_05\jre\lib\ext\dnsns.jar, C:\Java\jdk1.5.0_05\jre\lib\ext\localedata.jar, 
C:\Java\jdk1.5.0_05\jre\lib\ext\sunjce_provider.jar, C:\Java\jdk1.5.0_05\jre\lib\ext\sunpkcs11.jar, 
C:\eclipse\workspace\TestProjekt, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-antlr.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-bcel.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-bsf.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-log4j.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-oro.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-regexp.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-apache-resolver.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-commons-logging.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-commons-net.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-icontract.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-jai.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-javamail.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-jdepend.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-jmf.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-jsch.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-junit.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-launcher.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-netrexx.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-nodeps.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-starteam.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-stylebook.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-swing.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-trax.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-vaj.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-weblogic.jar, 
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-xalan1.jar, C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-xslp.jar, 
C:\eclipse\configuration\org.eclipse.osgi\bundles\6\1\.cp\lib\remoteAnt.jar, 
C:\eclipse\plugins\org.junit_3.8.1\junit.jar, C:\Java\jdk1.5.0_05\lib\tools.jar, 
C:\eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.1.2.jar]]
    [javac] [loading C:\eclipse\plugins\org.junit_3.8.1\junit.jar(junit/framework/TestCase.class)]
    [javac] [loading C:\eclipse\plugins\org.junit_3.8.1\junit.jar(junit/framework/Test.class)]
    [javac] [loading C:\Java\jdk1.5.0_05\jre\lib\rt.jar(java/lang/Object.class)]
    [javac] [loading C:\eclipse\plugins\org.junit_3.8.1\junit.jar(junit/framework/Assert.class)]
    [javac] [checking TestExample]
    [javac] [loading C:\Java\jdk1.5.0_05\jre\lib\rt.jar(java/lang/String.class)]
    [javac] [wrote C:\eclipse\workspace\TestProjekt\TestExample.class]
    [javac] [total 514ms]
test:
    [junit] Testsuite: TestExample
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec
[junitreport] Transform time: 764ms
all:
BUILD SUCCESSFUL
Total time: 2 seconds

Gruss
 

clemson

Bekanntes Mitglied
Hallo!

Zeig mal bitte deine build.xml; du muss nämlich dem junit task angeben, dass er testresults ausgeben soll, und wohin er diese speichern soll...

Code:
<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes">
	<formatter type="xml" />

	<test todir="${test.results}"  name="org.mypackage.myTestClass.class fork="true" />

	
	<batchtest todir="${test.results}" haltonerror="false" haltonfailure="false">
		<fileset dir="${path.to.classes}">
			<include name="org/mypackage/**/*Test.class" />
		</fileset>
	</batchtest>

</junit>

und die report seite(n) werden dann aus den generierten XML's im ordner ${test.results} abgelegt.

Code:
<junitreport todir="${test.report}">
	<fileset dir="${test.results}">
		<include name="TEST-*.xml" />
	</fileset>
	<report todir="${test.report}" format="frames" />
</junitreport>
 

pymote

Aktives Mitglied
hi, vielen dank, der erste schritt wäre getan. der report wurde erstellt.

jetzt habe ich meine testklasse in das package src/test verschoben.
die build.xml bleibt im projekt root. beim ausführen des ant-scripts wird ein report erstellt, allerdings bekomme ich einen fehler:
Code:
compile-test:
test:
    [junit] Running TestExample.class
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Test TestExample.class FAILED
[junitreport] Transform time: 812ms
all:
BUILD SUCCESSFUL
Total time: 2 seconds

im report steht zum fehler folgendes:
Code:
<error message="TestExample.class" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: TestExample.class
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
</error>

hier noch meine build.xml:
Code:
<?xml version="1.0" ?>
<project default="all">
  <property name="tst-dir" location="src/test" />
  <property name="report-dir" location="report" />
  <property name="TALK" value="true" />

  <path id="classpath.base">
  </path>
  <path id="classpath.test">
    <pathelement location="/WebRoot/WEB-INF/lib/junit.jar" />
    <pathelement location="${tst-dir}" />
    <path refid="classpath.base" />
  </path>

  <target name="compile-test">
    <javac srcdir="${tst-dir}"
           verbose="${TALK}"
           >
      <classpath refid="classpath.test"/>
    </javac>
  </target>
  <target name="clean-compile-test">
    <delete verbose="${TALK}">
      <fileset dir="${tst-dir}" includes="**/*.class" />
    </delete>
  </target>

  <target name="test" depends="compile-test">
  	
  	<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes">
  	   <formatter type="xml" />
  	   <test todir="${report-dir}"  name="TestExample.class" fork="true" /> 
    </junit>
  	
  	<junitreport todir="${report-dir}">
  	  <fileset dir=".">
  	    <include name="TEST-*.xml"/>
  	  </fileset>
  	  <report format="frames" todir="${report-dir}/html"/>
  	</junitreport>
  	
  </target>

  <target name="all" depends="test" />
  <target name="clean" depends="clean-compile-test" />
</project>
 

pymote

Aktives Mitglied
da bekomme ich allerdings folgenden fehler:
Code:
java.lang.ClassNotFoundException: test.TestExample.class 
at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:251) 
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:164)
hier noch meine überarbeitete build.xml:

Code:
<project default="all">
  <property name="test.class" location="src/test" />
  <property name="test.report" location="report" />
  <property name="test.results" location="results" />	
  <property name="TALK" value="true" />

  <path id="classpath.base">
  </path>
  <path id="classpath.test">
    <pathelement location="/WebRoot/WEB-INF/lib/junit.jar" />
    <pathelement location="${test.class}" />
    <path refid="classpath.base" />
  </path>

  <target name="compile-test">
    <javac srcdir="${test.class}"
           verbose="${TALK}"
           >
      <classpath refid="classpath.test"/>
    </javac>
  </target>
	
  <target name="clean-compile-test">
    <delete verbose="${TALK}">
      <fileset dir="${test.class}" includes="**/Test*.class" />
    </delete>
  </target>

  <target name="test" depends="compile-test">
  	
  	<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes">
  	   <formatter type="xml" />
  		<test todir="${test.results}"  name="test.TestExample.class" fork="true" />
    </junit>
  	
  	<junitreport todir="${test.report}">
  		<fileset dir="${test.results}">
  	    	<include name="TEST-*.xml"/>
  	  	</fileset>
		<report todir="${test.report}" format="frames" />
  	</junitreport>
  	
  </target>

  <target name="all" depends="test" />
	
  <target name="clean" depends="clean-compile-test" />
</project>

Habe ich was vergessen in den CLASSPATH aufzunehmen?

wenn ich im report auf properties der test.testExample.class gehe, sehe ich in meiner java.class.path nur folgende einträge:

C:\eclipse\plugins\org.junit_3.8.1\junit.jar;
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-launcher.jar;
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant.jar;
C:\eclipse\plugins\org.apache.ant_1.6.5\lib\ant-junit.jar

danke
 

pymote

Aktives Mitglied
was mir noch aufgefallen ist:
im report wird "test.TestExample" als Package und "class" als Klasse angesehen.
 

pymote

Aktives Mitglied
Hallo,
wenn ich .class weglasse wird test als package und TestExample als Klasse korrekt erkannt.
Allerdings gibts wieder ne ClassNotFoundException: test.TestExample
ich muss doch das Verzeichnis in dem meine Testklassen sind (src/test), explizit im classpath angeben. das hab auch getan, kann aber wie schon beschrieben diesen Pfad nicht bei "java.class.path" in den properties finden.
 

pymote

Aktives Mitglied
Ich habs!

Ich habe nicht beachtet dass ich auch im "test" tag den classpath angeben muss. So gehts:
Code:
<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes">
  	<formatter type="xml" />
  	<classpath refid="classpath.test"/>
  	<test todir="${test.results}" name="test.TestExample" fork="yes"/>
</junit>
danke
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben