You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Mohamed, Haneef" <Ha...@G1.com> on 2002/04/16 19:35:40 UTC

jpcoverage/junit intergration: how do I capture junit coverage wi th with JProbe?

Hello everyone!

Here is the problem I am encountering:

Aim
To run junit tests and capture code coverage metrics with jprobe as part of
the build process [pre-deployment] 
via ant

What I have tried
1. tried to run junit as a nested element within jpcoverage -- failed

2. tried to do an 'antcall' to run junit -- failed

3. The only thing that worked [this is my fallback position] is to pass
junit.textui.TestRunner,
one arg at a time, each TestClass, passing one arg is shown below:

  <target name="hm">
            <jpcoverage home="${jpcoveragehome}"
	     	warnlevel="9"
	     	recordfromstart="coverage" snapshotdir="${build}/coverage"
		workingdir="${test.classes}"
	     	classname="junit.textui.TestRunner">
			<classpath refid="c1p.test.classpath"/>
			<arg>
                		<filters defaultexclude="false">
                    			<include class="*Test*" method="*"/>
                		</filters>
			</arg>
	    </jpcoverage>
    </target>

Notes
1. Our junit testclasses do not have a main(...), that would have made my
life a lot easier
2. I am appending the junit target at the end as well

Any suggestions would be greatly appreciated.

thanks,

Haneef Mohamed


=========
junit target
=========
<target name="test" depends="jar-test, jar-server"
		description="Execute Unit Tests">

		<mkdir dir="${build}/reports"/>
		
		<junit failureProperty="junit.failed">
			<classpath refid="c1p.test.classpath"/>
			<formatter type="xml" />
			
			<batchtest todir="${test.reports}">
				    <fileset dir="${test.classes}">
      					<include name="**/Test*.class" />
      					<exclude name="**/TestAll.class" />
      					<exclude name="**/Test*$$*.class" />
					<exclude
name="**/*TestCase*.class"/>
    				    </fileset>
			</batchtest>
			
		</junit>
		
		<junitreport todir="${test.reports}">
			<fileset dir="${test.reports}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="noframes" todir="${test.reports}"/>
		</junitreport>
</target>


Re: jpcoverage/junit intergration: how do I capture junit coverage with with JProbe?

Posted by Gordon Tyler <go...@sitraka.com>.
First, a disclaimer: I work at Sitraka (who produces JProbe) but I do not
work on JProbe itself. I am part of another team at Sitraka which merely
uses JProbe Coverage with JUnit tests. So I can't give support on JProbe.

We don't use the jpcoverage or junit tasks because of the limitations that
you've pointed out but rather we execute jplauncher.exe using an <exec> task
and pass all the appropriate command-line arguments. Also, we don't execute
TestRunner directly, but rather a class which we wrote that automatically
"discovers" all the test classes in our packages and builds a TestSuite
which it then runs using TestRunner.

Here's the <exec> task that we use:

<property name="coverage.home" value="${env.COVERAGE_HOME}"/>

<exec executable="${coverage.home}/jplauncher.exe">
        <arg value="-classpath"/>
        <arg value="YOUR_CLASSPATH_HERE"/>
        <arg value="-jp_function=coverage"/>
        <arg value="-jp_java_home=${java.home}"/>
        <arg value="-jp_java_exe=${java.home}/bin/java.exe"/>
        <arg value="-jp_vm=java2"/>
        <arg value="-jp_final_snapshot=coverage"/>
        <arg value="-jp_ignore_abstract=true"/>
        <arg value="-jp_record_from_start=coverage"/>
        <arg value="-jp_output_file=YOUR_OUTPUT_FILENAME_HERE"/>
        <arg value="-jp_snapshot_dir=YOUR_SNAPSHOT_DIRECTORY_HERE"/>
        <arg value="-jp_working_dir=YOUR_BUILD_WORKING_DIRECTORY_HERE"/>
        <arg
value="-jp_filter=*.*:E,com.acme.product*.*:I,com.acme.product.AutoTest:E"/>
        <arg value="com.acme.product.AutoTest"/>
        <arg value="-o"/>
        <arg value="YOUR_LOG_FILENAME_HERE"/>
</exec>

The jp_working_dir option should point to a directory where your tests would
expect to be running from, so that they can find data files, etc. if
necessary. So in our case that would be our build/dist directory which
contains the jars and data files of our application.

The jp_filter option should be changed to use the correct includes and
excludes for your code.

com.acme.product.AutoTest is the fictional name of the "test discovery and
execution" class that I described earlier.

I don't actually use this myself, it's used by the QA guys on the team, so
I'm not 100% sure of how it all works ;) It's used in the context of a
nightly build where there isn't a human to observe it, so I don't think it
displays the Coverage UI.

Ciao,
Gordon

----- Original Message -----
From: "Mohamed, Haneef" <Ha...@G1.com>
To: <an...@jakarta.apache.org>
Sent: Tuesday, April 16, 2002 1:35 PM
Subject: jpcoverage/junit intergration: how do I capture junit coverage with
with JProbe?


> Hello everyone!
>
> Here is the problem I am encountering:
>
> Aim
> To run junit tests and capture code coverage metrics with jprobe as part
of
> the build process [pre-deployment]
> via ant



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>