1

I am integrating junit test cases with my current project that uses ant build files. I have added a few test cases, and they are running perfectly as part of build process. I need to generate a detailed and relevant report of junit along with build. Inside <junit>, I am using <formatter>. I am facing following issues:

  1. If I use <formatter type="plain">, it contains very limited information.
  2. If I use <formatter type="xml>, it prints too many properties.
  3. I tried writing a custom formatter using org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter. For this, I need to add ant-x.x.x.jar and ant-junit-x.x.x.jar in build file <classpath>. It gives "two different ant versions are present"

Question-1: Is there any way by which we can restrict or filter the XML elements to be printed in reports, maybe by overriding XML formatter or some other way?

Question-2: How can I avoid the above exception of "two different ant version"?

I would prefer if there is some option for question-1.


[UPDATE-1] My JUnit task in Ant:

<target name="unit_testing" depends="binary" description="Unit Testing">
        <!-- Compile the java code from ${src} into ${build_main} -->
        <javac srcdir="${codebase_test}" destdir="${build_test}"
            encoding="cp1252" includeantruntime="false"
            bootclasspath="C:/Program Files (x86)/Java/jdk1.5.0_07/jre/lib/rt.jar;C:/Program Files/Java/jdk1.5.0_07/jre/lib/rt.jar;"
            source="1.5" target="1.5">
            <classpath refid="classpath_main" />
            <classpath refid="classpath_test" />
            <classpath>
                <pathelement location="${binary}/binary_x.x.x.jar" />
            </classpath>
        </javac>

        <junit fork="yes" haltonfailure="yes">
            <!-- set useFile="true" if output required in files -->
            <formatter type="xml" usefile="true" />

            <classpath refid="classpath_main" />
            <classpath refid="classpath_test" />
            <classpath>
                <pathelement path="${build_test}" />
                <pathelement location="${binary}/binary_x.x.x.jar" />
            </classpath>

            <batchtest todir="${results_test}">
                <fileset dir="${build_test}">
                    <include name="**/*Test.class" />
                </fileset>
            </batchtest>

        </junit>
    </target>
Amber Beriwal
  • 1,568
  • 16
  • 30

1 Answers1

1

Question 1

Consider using the <xslt> task to take the XML files generated by <junit> as input and use XSLT to generate another XML file as output.

See Custom JUnit Report? for an example of using XSLT to generate other files.

Question 2

There shouldn't be a need to specify either ant-x.x.x.jar or ant-junit-x.x.x.jar on the <classpath> passed to <junit>.

By default, includeantruntime is true for <junit>. That means ant-x.x.x.jar and ant-junit-x.x.x.jar will already be on the CLASSPATH given to forked JUnit processes.

Removing ant-x.x.x.jar and ant-junit-x.x.x.jar from <classpath> will avoid the multiple versions of ant detected in path for junit warning.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • `includeantruntime` was `false` in my file. Will try by setting it `true`. I didn't get the first answer. I have never used `XSTL` so how to use `junitreport` or `XSTL` in ant file? I have updated my ant code in question. – Amber Beriwal Mar 27 '17 at 03:44
  • I am able to get reports in frames and the system properties ... will try with custom XSTL... – Amber Beriwal Mar 27 '17 at 03:50
  • At many places, I have seen `@*|b/@*`, what does `b/@*` mean in that? – Amber Beriwal Mar 27 '17 at 05:36
  • @AmberBeriwal `b/@*` means "match the attributes of elements named ``. For example, in the XML fragment ``, `b/@*` matches the `b1` and `b2` attributes of the two `` elements. – Chad Nouis Mar 27 '17 at 13:39
  • OK..Now I get it....thanks buddy...your answer really helped me out to get a quick result. – Amber Beriwal Mar 28 '17 at 15:59