Jacoco Code Coverage for Selenium UI functional tests

2,071 views
Skip to first unread message

nes...@gmail.com

unread,
Jun 18, 2015, 7:31:00 AM6/18/15
to jac...@googlegroups.com, Rohit....@ctfs.com
We are in the process of measuring code coverage for Selenium UI functional tests using Jacoco having ANT build. TestNG framework has been used to manage and trigger selenium test cases. we are using [JDK:1.6], [ANT:1.7.1], [jacoco: 0.7.5] and Web-application runs on "Websphere.

Note: Script compiles the project first and then triggers the selenium tests against the application from compiled code-base.

Please refer the below script and let us know, where and what are we doing the mistake.
-----------------------------Script Begins-----------------------------

<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant file for TestNG" default="all" basedir="." xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">

<taskdef resource="net/sf/ant4eclipse/antlib.xml" />

<path id="class.path">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${bin.dir}" />
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${it.test.report.dir}" />
</target>

<target name="init">
<mkdir dir="${it.test.report.dir}" />
</target>

<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="X:/.../.../.../.../jacocoant.jar"/>
<classpath path="X:/.../.../.../.../jacocoagent.jar"/>
</taskdef>

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="class.path">
</taskdef>

<target name="report">

<jacoco:agent property="agentvmparam" destfile="X:/.../.../.../.../jacoco.exec" includes="**/*.class" output="file" dumponexit="true" classdumpdir="X:/.../.../.../.../jclasses"/>

<jacoco:coverage>
<testng haltonfailure="yes" classpathref="class.path">
<xmlfileset dir="." includes="Demotestng.xml" />
<classpath refid="class.path" />
<jvmarg value="-Xshareclasses:none"/>
<jvmarg value="${agentvmparam}"/>
</testng>
</jacoco:coverage>

<jacoco:report>
<executiondata>
<file file="X:/.../.../.../.../jacoco.exec"/>
</executiondata>

<structure name="Example Integration Test Project">
<classfiles>
<fileset dir="X:/.../.../.../.../servlets">
<include name="**/*.class" />
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="X:/.../.../src/.../.../servlets">
<include name="**/*.java" />
</fileset>
</sourcefiles>

</structure>
<html destdir="jreport" />
</jacoco:report>
</target>

<target name="all" depends="clean,compilepresentation,report" />

</project>
--------------- Script Ends---------------------------------------

Made all the required changes and continuously trying with potential changes. However, unable to meet the objective of getting the coverage report.

Report generated as "Missed Instructions: All(RED Horizontal pipe), Coverage:0%:: Missed branchess: All(RED Horizontal pipe), Coverage:0%"

Kindly help me on this, it's been a week, we're unable to reach the goal.

Thanks

Marc Hoffmann

unread,
Jun 18, 2015, 9:09:47 AM6/18/15
to jac...@googlegroups.com
Hi,

one problem I spot immediately is the includes filter:

includes="**/*.class"

The filter refers to VM class name, not class files. If you want to
cover all classes the correct syntax is

includes="*"

Which is default anyways.

regrads,
-marc

nes...@gmail.com

unread,
Jun 18, 2015, 10:03:08 AM6/18/15
to jac...@googlegroups.com, jagadeesha....@ness.com
Thanks Marc for the quick reply. Made the change as you suggested, however it seems it's trying to instrument all files including TestNG and Apache files. Throwing exception like, it's huge stack trace...
report:
[jacoco:coverage] Enhancing testng with coverage
[testng] java.lang.instrument.IllegalClassFormatException: Error while instrumenting class org/testng/TestNG.
[testng] at org.jacoco.agent.rt.internal_13ff51f.CoverageTransformer.transform(CoverageTransformer.java:89)
[testng] at sun.instrument.TransformerManager.transform(TransformerManager.java:181)
[testng] at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:377)
[testng] at java.lang.ClassLoader.defineClassImpl(Native Method)
[testng] at java.lang.ClassLoader.defineClass(ClassLoader.java:262)
[testng] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
[testng] at java.net.URLClassLoader.defineClass(URLClassLoader.java:540)
[testng] at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
[testng] at java.net.URLClassLoader.access$300(URLClassLoader.java:79)
[testng] at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1038)
[testng] at java.security.AccessController.doPrivileged(AccessController.java:314)
[testng] at java.net.URLClassLoader.findClass(URLClassLoader.java:429)
[testng] at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665)
[testng] at java.lang.ClassLoader.loadClass(ClassLoader.java:644)
[testng] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
[testng] at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
[testng] Caused by: java.io.IOException: Error while instrumenting class org/testng/TestNG.
[testng] at org.jacoco.agent.rt.internal_13ff51f.core.instr.Instrumenter.instrumentError(Instrumenter.java:152)
[testng] at org.jacoco.agent.rt.internal_13ff51f.core.instr.Instrumenter.instrument(Instrumenter.java:103)
[testng] at org.jacoco.agent.rt.internal_13ff51f.CoverageTransformer.transform(CoverageTransformer.java:87)
[testng] ... 15 more
[testng] Caused by: java.lang.IllegalStateException: Class org/testng/TestNG is already instrumented.

Marc Hoffmann

unread,
Jun 19, 2015, 3:34:30 AM6/19/15
to jac...@googlegroups.com
Hi,

ok, you could narrow down the instrumentation to your project by
specifying

includes="com.yourcompany.*"

But this is not the cause of the exception. There is another problem
with your build script: You define a JaCoCo agent via JVM args and use
the jacoco:coverage task. This will result in two JaCoCo agents
configured for your tests and causes " Class
xy is already instrumented."

Please take a look at our documentation:
http://www.eclemma.org/jacoco/trunk/doc/

It includes a working Ant example:
http://www.eclemma.org/jacoco/trunk/doc/examples/build/build.xml

regards,
-marc

nes...@gmail.com

unread,
Jun 19, 2015, 4:45:18 AM6/19/15
to jac...@googlegroups.com, jagadeesha....@ness.com
Yes Marc, you're right. Exceptions went off now.

On the other hand, made below changes and ran Jenkins job,

Case-1: Removed <jacoco:coverage> </jacoco:coverage> and ran the script

Case-2: Removed <jacoco:agent property="agentvmparam" destfile="X:/.../.../.../.../jacoco.exec" includes="my.company.*" output="file" dumponexit="true" classdumpdir="X:/.../.../.../.../jclasses"/> and ran the build

Both the above cases resulted in same old result. Am I missing anything here?

Request other group members who've succeeded in getting code coverage for selenium UI tests to provide insight into this issue.

Thanks

nes...@gmail.com

unread,
Jun 19, 2015, 4:55:06 AM6/19/15
to jac...@googlegroups.com, nes...@gmail.com, jagadeesha....@ness.com
Marc,

Also looked at Sessions, it lists the Sessions, Start Time and End Time and says No execution data available.

Thanks

nes...@gmail.com

unread,
Jun 23, 2015, 2:03:12 AM6/23/15
to jac...@googlegroups.com, nes...@gmail.com, Rohit....@ctfs.com
Marc,Kindly help me. Thanks

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages