Avatar of AnjaliW
AnjaliW
 asked on

maven cobertura plugin

i am running JUNIT test and want code coverage for those testcase .
added "cobertura-maven-plugin" for code coverage and used following command

Command used:           "mvn clean test cobertura:cobertura -X >>out.log" .

it is created cobeture folder inside target folder.

But don't see any reports generated which says your % of code is covered....

WHere should I check these reports..
 POM>xml is attached.
pom.xml
Programming Languages-Other

Avatar of undefined
Last Comment
AnjaliW

8/22/2022 - Mon
warturtle

Have you checked here??

${project.basedir}/target/site/cobertura
AnjaliW

ASKER
I have checked here " ${project.basedir}/target/cobertura ".Nothing available here..


there is no site directory in my project since i am just running JUNIT and using code coverage on it.

here are logs which says "cobertura.ser " couln't find...

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 38.579 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] <<< cobertura-maven-plugin:2.5:cobertura (default-cli) @ com.ofss.fc.junit.origination <<<
[INFO]
[INFO] --- cobertura-maven-plugin:2.5:cobertura (default-cli) @ com.ofss.fc.junit.origination ---
[DEBUG] Configuring mojo org.codehaus.mojo:cobertura-maven-plugin:2.5:cobertura from plugin realm ClassRealm[plugin>org.codehaus.mojo:cobertura-maven-plugin:2.5, parent: sun.misc.Launcher$AppClassLoader@12360be0]
[DEBUG] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[DEBUG] Setting property: site.resource.loader.class => 'org.codehaus.plexus.velocity.SiteResourceLoader'.
[DEBUG] Setting property: velocimacro.messages.on => 'false'.
[DEBUG] Setting property: resource.loader => 'classpath,site'.
[DEBUG] Setting property: runtime.log.invalid.references => 'false'.
[DEBUG] Setting property: resource.manager.logwhenfound => 'false'.
[DEBUG] Setting property: velocimacro.permissions.allow.inline.to.replace.global => 'true'.
[DEBUG] *******************************************************************
[DEBUG] Starting Apache Velocity v1.5 (compiled: 2007-02-22 08:52:29)
[DEBUG] RuntimeInstance initializing.
[DEBUG] Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
[DEBUG] LogSystem has been deprecated. Please use a LogChute implementation.
[DEBUG] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.SiteResourceLoader
[DEBUG] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[DEBUG] Default ResourceManager initialization complete.
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[DEBUG] Created '20' parsers.
[DEBUG] Velocimacro : initialization starting.
[DEBUG] Velocimacro : allowInline = true : VMs can be defined inline in templates
[DEBUG] Velocimacro : allowInlineToOverride = true : VMs defined inline may replace previous VM definitions
[DEBUG] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
[DEBUG] Velocimacro : autoload off : VM system will not automatically reload global library macros
[DEBUG] Velocimacro : Velocimacro : initialization complete.
[DEBUG] RuntimeInstance successfully initialized.
[DEBUG] Configuring mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.5:cobertura' with basic configurator -->
[DEBUG]   (f) aggregate = false
[DEBUG]   (f) dataFile = D:\code\project\testprojects\com.ofss.fc.junit.\target\cobertura\cobertura.ser
[DEBUG]   (f) encoding = ISO-8859-1
[DEBUG]   (f) formats = [html, xml]
[DEBUG]   (f) maxmem = 1024m
[DEBUG]   (f) omitGplFiles = false
[DEBUG]   (f) outputDirectory = D:\code\project\testprojects\com.ofss.fc.junit.origination\target\site\cobertura
[DEBUG]   (f) pluginClasspathList = [org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.5:, net.sourceforge.cobertura:cobertura:jar:1.9.4.1:compile, oro:oro:jar:2.0.8:compile, asm:asm:jar:3.0:compile, asm:asm-tree:jar:3.0:compile, log4j:log4j:jar:1.2.9:compile, org.apache.ant:ant:jar:1.7.0:compile, org.apache.ant:ant-launcher:jar:1.7.0:compile, net.sourceforge.cobertura:cobertura-runtime:pom:1.9.4.1:compile, urbanophile:java-getopt:jar:1.0.9:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.0.6:compile, org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7:compile, org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4.2:compile, commons-validator:commons-validator:jar:1.2.0:compile, commons-beanutils:commons-beanutils:jar:1.7.0:compile, commons-digester:commons-digester:jar:1.6:compile, commons-logging:commons-logging:jar:1.0.4:compile, xml-apis:xml-apis:jar:1.0.b2:compile, org.apache.maven.doxia:doxia-core:jar:1.0:compile, org.apache.maven.doxia:doxia-site-renderer:jar:1.0:compile, org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile, org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile, org.apache.velocity:velocity:jar:1.5:compile, org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile, commons-collections:commons-collections:jar:3.2:compile, org.apache.maven.doxia:doxia-module-apt:jar:1.0:compile, org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xdoc:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.2:compile, org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]
[DEBUG]   (f) project = MavenProject: ngp.flexcube.com.ofss.fc.cz.nab.application:com.ofss.fc.junit.:1.0 @ D:\code\project\testprojects\com.ofss.fc.junit\pom.xml
[DEBUG]   (f) quiet = false
[DEBUG]   (f) reactorProjects = [MavenProject: com.ofss.fc.cz.nab.application:com.ofss.fc.cz.nab.application:1.0 @ D:\code\pom.xml, MavenProject: ngp.flexcube.com.ofss.fc.cz.nab.application:com.ofss.fc.junit.origination:1.0 @ D:\code\project\testprojects\com.ofss.fc.junit\pom.xml]
[DEBUG] -- end configuration --
[INFO] Not executing cobertura:report as the cobertura data file (D:\code\project\testprojects\target\cobertura\cobertura.ser) could not be found
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] CZ NGP Artifacts .................................. SUCCESS [1:41.647s]
[INFO] CZ Artifact: com.ofss.fc.junit........ SUCCESS [1:45.704s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:27.647s
[INFO] Finished at: Mon May 21 16:12:00 IST 2012
[INFO] Final Memory: 49M/199M
[INFO] -------------------------------
warturtle

you need to specifically mention within the cobetura code where the .ser file is, that might allow the vm to find it.

currently, its looking at this location:

D:\code\project\testprojects\com.ofss.fc.junit.\target\cobertura\cobertura.ser

maybe try inserting a <property> element within the pom.xml, inside the cobertura section and specify the exact path to the .ser file. That should solve this issue.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
AnjaliW

ASKER
But .ser file should automatically placed with the help of cobetura plugin ...isn't it?

If not then where do i get that .ser file and how to put that..
warturtle

this .ser file will be created when cobetura is successfully able to instrument the compiled classes. i am assuming that you are using maven 2, so please have a look at this tutorial which should give you help:

http://mojo.codehaus.org/cobertura-maven-plugin/index.html
AnjaliW

ASKER
well I have Maven 3.. in D drive "apache-maven-3.0.4".
Does it require target path which says which classes need to do code coverage or JUNIT has to cover???
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
warturtle

Try including the maven-site plugin as well within the pom.xml, see the below link:

http://stackoverflow.com/questions/6931360/what-is-the-proper-way-to-use-cobertura-with-maven-3-0-2
AnjaliW

ASKER
I have tried above site plugin...And it is creating site folder with this structure:"target\site\cobertura"
.
But doesn't creat report.
Well in my scenario:
 I am just compiling JUNIT java class and target_classes/**/*.class hass been generated after JUNIT compile and runs and get JUNIT repot.Whatever main jave sources required to run tests ,it is provided by jars.So there are no classes available in target/classes folder.

So does it mean to run code coverage  we need target/classes/... /*.class  .
Or it coverage can use jars also to do code coverage reports????????

Thanks!


[INFO]
[INFO] <<< cobertura-maven-plugin:2.4:cobertura (default-cli) @ com.ofss.fc.junit.origination <<<
[INFO]
[INFO] --- cobertura-maven-plugin:2.4:cobertura (default-cli) @ com.ofss.fc.junit.origination ---
[DEBUG] Configuring mojo org.codehaus.mojo:cobertura-maven-plugin:2.4:cobertura from plugin realm ClassRealm[plugin>org.codehaus.mojo:cobertura-maven-plugin:2.4, parent: sun.misc.Launcher$AppClassLoader@12360be0]
[DEBUG] Configuring mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.4:cobertura' with basic configurator -->
[DEBUG]   (f) dataFile = D:\code\project\testprojects\com.ofss.fc.junit.origination\target\cobertura\cobertura.ser
[DEBUG]   (f) encoding = ISO-8859-1
[DEBUG]   (f) maxmem = 1024m
[DEBUG]   (f) outputDirectory = D:\\code\project\testprojects\com.ofss.fc.junit.origination\target\site\cobertura
[DEBUG]   (f) pluginClasspathList = [org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.4:, net.sourceforge.cobertura:cobertura:jar:1.9.4.1:compile, oro:oro:jar:2.0.8:compile, asm:asm:jar:3.0:compile, asm:asm-tree:jar:3.0:compile, log4j:log4j:jar:1.2.9:compile, org.apache.ant:ant:jar:1.7.0:compile, org.apache.ant:ant-launcher:jar:1.7.0:compile, net.sourceforge.cobertura:cobertura-runtime:pom:1.9.4.1:compile, urbanophile:java-getopt:jar:1.0.9:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.0:compile, doxia:doxia-sink-api:jar:1.0-alpha-4:compile, org.apache.maven.reporting:maven-reporting-impl:jar:2.0:compile, commons-validator:commons-validator:jar:1.1.4:compile, doxia:doxia-core:jar:1.0-alpha-4:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.2:compile]
[DEBUG]   (f) project = MavenProject: .com.ofss.fc.cz.nab.application:com.ofss.fc.junit.origination:1.0 @ D:\\code\project\testprojects\com.ofss.fc.junit.origination\pom.xml
[DEBUG]   (f) quiet = false
[DEBUG] -- end configuration --
[INFO] Not executing cobertura:report as the cobertura data file (D:\code\project\testprojects\com.ofss.fc.junit.origination\target\cobertura\cobertura.ser) could not be found
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] CZ NGP Artifacts .................................. SUCCESS [1.163s]
[INFO] CZ Artifact: com.ofss.fc.junit.origination ........ SUCCESS [59.986s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:01.510s
[INFO] Finished at: Tue May 22 09:32:18 IST 2012
[INFO] Final Memory: 32M/337M
ASKER CERTIFIED SOLUTION
warturtle

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
AnjaliW

ASKER
Yes i did added ...instrumentation part ..but it says no classes for instrumentations::following code  is there:::: it is looking instumentation here "Basedir: D:\code\project\testprojects\com.ofss.fc.junit.origin\target\generated-classes\cobertura"  .

But my test classes are  in" target/testclasses/com...../*.class    " here.

Code and logs are given:


plugin>      
     <groupId>org.codehaus.mojo</groupId>    
       <artifactId>cobertura-maven-plugin</artifactId>  
       <version>2.3</version>      
       <configuration>        
                 
            <instrumentation>      
            <includes>        
                  <include>${project.build.directory}/test-classes/**/*.class</include>  
            </includes>              
            </instrumentation>      
       </configuration>        
     <executions>          
            <execution>          
                  <id>clean</id>        
                  <phase>pre-site</phase>  
                  <goals>                
                        <goal>clean</goal>      
                  </goals>            
            </execution>        
            <execution>          
                  <id>instrument</id>  
                  <phase>site</phase>    
                  <goals>                
                        <goal>instrument</goal>  
                        <goal>cobertura</goal>    
                           
                  </goals>              
            </execution>          
       </executions>      
       </plugin>




Logs Are:

[DEBUG] Configuring mojo org.codehaus.mojo:cobertura-maven-plugin:2.3:instrument from plugin realm ClassRealm[plugin>org.codehaus.mojo:cobertura-maven-plugin:2.3, parent: sun.misc.Launcher$AppClassLoader@12360be0]
[DEBUG] Configuring mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.3:instrument' with basic configurator -->
[DEBUG]   (f) check = org.codehaus.mojo.cobertura.configuration.ConfigCheck@2ca2e19e
[DEBUG]   (f) dataFile = D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target\cobertura\cobertura.ser
[DEBUG]   (f) includes = [D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target/test-classes/**/*.class]
[DEBUG]   (f) instrumentation = <ConfigInstrumentation basedir="D:\workspace_ngp\code" includes="D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target/test-classes/**/*.class" />
[DEBUG]   (f) maxmem = 1024m
[DEBUG]   (f) pluginClasspathList = [org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.3:, net.sourceforge.cobertura:cobertura:jar:1.9.2:compile, oro:oro:jar:2.0.8:compile, asm:asm:jar:3.0:compile, asm:asm-tree:jar:3.0:compile, log4j:log4j:jar:1.2.9:compile, org.apache.ant:ant:jar:1.7.0:compile, org.apache.ant:ant-launcher:jar:1.7.0:compile, net.sourceforge.cobertura:cobertura-runtime:pom:1.9.2:compile, urbanophile:java-getopt:jar:1.0.9:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.0:compile, doxia:doxia-sink-api:jar:1.0-alpha-4:compile, org.apache.maven.reporting:maven-reporting-impl:jar:2.0:compile, commons-validator:commons-validator:jar:1.1.4:compile, doxia:doxia-core:jar:1.0-alpha-4:compile, org.codehaus.plexus:plexus-utils:jar:1.1:compile]
[DEBUG]   (f) project = MavenProject: ngp.flexcube.com.ofss.fc.cz.nab.application:com.ofss.fc.junit.origination:1.0 @ D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\pom.xml
[DEBUG]   (f) quiet = false
[DEBUG] -- end configuration --
[DEBUG] Config : <ConfigInstrumentation basedir="D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target\generated-classes\cobertura" includes="D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target/test-classes/**/*.class" />
[DEBUG] Basedir: D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target\generated-classes\cobertura
[DEBUG] Include: D:\workspace_ngp\code\project\testprojects\com.ofss.fc.junit.origination\target/test-classes/**/*.class
[DEBUG] Exclude: **/*~,**/#*#,**/.#*,**/%*%,**/._*,**/CVS,**/CVS/**,**/.cvsignore,**/SCCS,**/SCCS/**,**/vssver.scc,**/.svn,**/.svn/**,**/.arch-ids,**/.arch-ids/**,**/.DS_Store
[WARNING] No files to instrument.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] CZ NGP Artifacts .................................. SUCCESS [0.951s]
[INFO] CZ Artifact: com.ofss.fc.junit.origination ........ SUCCESS [51.001s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.249s
[INFO] Finished at: Tue May 22 16:40:54 IST 2012
[INFO] Final Memory: 31M/290M
[INFO] --------------------------------
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck