Empty Junit posts by ant

I am trying to use ant to run junit tests and generate reports. I can run tests successfully, but the report files are empty.

What am I doing wrong?

This is my build.xml file:

<project name="JunitTest" default="test" basedir="."> <property name="testdir" location="." /> <property name="srcdir" location="." /> <property name="full-compile" value="true" /> <property name="test.reports" value="./reports" /> <path id="classpath.base"/> <path id="classpath.test"> <pathelement location="${testdir}" /> <pathelement location="${srcdir}" /> <path refid="classpath.base" /> </path> <target name="clean" > <delete verbose="${full-compile}"> <fileset dir="${testdir}" includes="**/*.class" /> </delete> ` </target> <target name="compile" depends="clean"> <javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}" > <classpath refid="classpath.test"/> </javac> </target> <target name="test" depends="compile"> <junit> <classpath refid="classpath.test" /> <formatter type="brief" usefile="false" /> <test name="com.tests.nav1" /> </junit> <junitreport todir="${test.reports}"> <fileset dir="${test.reports}"> <include name="TEST-*.xml" /> </fileset> <report todir="${test.reports}" /> </junitreport> </target> </project> 

and this is the output on the console:

 [junit] Using CLASSPATH C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src;C:\jars\junit.jar;C:\ant\lib\ant-launcher.jar;C:\ant\lib\ant.jar;C:\ant\lib\ant-junit.jar;C:\ant\lib\ant-junit4.jar [junit] Testsuite: com.tests.nav1 [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 48.187 sec [junit] ------------- Standard Output --------------- [junit] testnav2 [junit] ------------- ---------------- --------------- [junitreport] Using class org.apache.tools.ant.taskdefs.optional.TraXLiaison [junitreport] Processing C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\reports\TESTS-TestSuites.xml to C:\Users\pmahajan\AppData\Local\Temp\null236099757 [junitreport] Loading stylesheet jar:file:/C:/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 330ms [junitreport] Deleting: C:\Users\pmahajan\AppData\Local\Temp\null236099757 BUILD SUCCESSFUL Total time: 49 seconds 
+4
source share
4 answers

If you look at the ant fragment, there are several problems:

  • You set usefile=false , which means that no output file is created
  • You set formatter type=brief , which will print detailed information only for failed tests
  • You also need to specify todir - the folder in which the report should be in the <test> - the current folder is used by default. This should match the folder you are using in <junitreport> .

You can try the following updated <junit> section ...

  <junit> <classpath refid="classpath.test" /> <formatter type="xml"/> <test name="com.tests.nav1" todir="${test.reports}"/> </junit> 
+7
source
  1 <target name="test" depends="compile"> 2 <junit> 3 <classpath refid="classpath.test" /> 4 <formatter type="brief" usefile="false" /> 5 <test name="com.tests.nav1" /> 6 </junit> 7 <junitreport todir="${test.reports}"> 8 <fileset dir="${test.reports}"> 9 <include name="TEST-*.xml" /> 10 </fileset> 11 <report todir="${test.reports}" /> 12 </junitreport> 13 </target> 

The above segment is your encoded needs after the changes.

  • You must specify the option in the directory on the 5th line (for example, todir = $ {data.reports})
  • On line 8, the specified directory must contain .reports data.
  • The 11th line should contain an option format with value frames (format = "frames").
+2
source

The ant JUnit Task doc gives you an example that might help you (since it seems to be doing exactly what you are trying to achieve)

 <junit printsummary="yes" haltonfailure="yes"> <classpath> <pathelement location="${build.tests}"/> <pathelement path="${java.class.path}"/> </classpath> <formatter type="plain"/> <test name="my.test.TestCase" haltonfailure="no" outfile="result"> <formatter type="xml"/> </test> <batchtest fork="yes" todir="${reports.tests}"> <fileset dir="${src.tests}"> <include name="**/*Test*.java"/> <exclude name="**/AllTests.java"/> </fileset> </batchtest> </junit> 

Runs my.test.TestCase on the same VM, ignoring the given CLASSPATH; if this test fails, a warning is displayed. In addition to the usual text test results for this test, the XML result will be output in result.xml. Then, for each match file in the directory defined for $ {src.tests}, the test runs in a separate virtual machine. If the test fails, the build process will be interrupted. Results are collected in files named TEST-name.txt and are recorded in $ {reports.tests}.

The document states that printsummary can take the values on and off , but they use yes in the example, which is on the same page, so I think it is accepted too.

+1
source

Try formatting with xml

  <formatter type="${junit.format}"/> 

where junit.format is a property with an appropriate value.

0
source

Source: https://habr.com/ru/post/1384256/


All Articles