Empty Junit reports from ant

后端 未结 4 1531
时光取名叫无心
时光取名叫无心 2021-01-06 07:09

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

What am I doing wrong ?

相关标签:
4条回答
  • 2021-01-06 07:41

    If you look at the ant snippet, there are a few issues:

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

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

        <junit>
            <classpath refid="classpath.test" />
            <formatter type="xml"/>
            <test name="com.tests.nav1" todir="${test.reports}"/>
        </junit>
    
    0 讨论(0)
  • 2021-01-06 07:49

    The ant JUnit Task doc gives this example that might help you (as it apparently does exactly what you're 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 in the same VM, ignoring the given CLASSPATH; only a warning is printed if this test fails. In addition to the plain text test results, for this test a XML result will be output to result.xml. Then, for each matching file in the directory defined for ${src.tests} a test is run in a separate VM. If a test fails, the build process is aborted. Results are collected in files named TEST-name.txt and written to ${reports.tests}.

    It is specified in the doc that printsummary can take values on and off, but they're using yes in the example which is on the same page, so I guess it's accepted too.

    0 讨论(0)
  • 2021-01-06 07:58

    Please try formatter with "xml"

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

    where junit.format is property with appropriate value.

    0 讨论(0)
  • 2021-01-06 07:59
       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 of your coded needs following changes.

    1. You have to specify the to directory option in the 5th line( for example todir = ${data.reports} )
    2. In the 8th line the directory specified must me data.reports.
    3. The 11th line must contain the option format with the value frames (format="frames").
    0 讨论(0)
提交回复
热议问题