Friday, April 20, 2012

Cobertura Setup in MultiModule Maven With Jenkins (Draft)


Why we need a code coverage analysis for functional testing?
Reason is simple, tests which are generated out of a requirement specification just tests the functionality and satisfy when it meets the acceptance criteria. But when you see the overall tests which are resulted for the application, you can see lot of dependencies which are never tested at all.
Coverage analysis gives you a very solid statistics saying that these are the tests performed in the system and these are the statements or branches which are executed and these are not at all touched. This will help in tremendously improving the overall testcases which are written for the whole system by covering the untouched by analyzing the coverage report.
 
Out of Scope
Scope
Things Used
Eclipse Project Creation
Maven configurations
Sample Project
Maven Initial Setup
Instrumenting Code
Cobertura
JUnit Selenium Tests
Jenkins configurations
Maven
Cobertura Competencies


JUnit




Jenkins


STEP 1 : Create a simple multi-module maven web project to try it or use the one which you want to report coverage
Fig 1
  • Take a help from the maven example here to create a multi-module maven web project
  • Considered Fig 1 as a simple structure of such multi-module web project
  • Cobertura module - specifically added to generate the coverage report






STEP 2 : Modify the pom files to do the instrumentation of the codes


 do-instrumentation
 
  
   
    org.codehaus.mojo
    cobertura-maven-plugin
    ${cobertura.plugin.version}
    
    
    
     
      instrument-code
      process-classes
      
       instrument
      
      
       true
      
     
    
   
  
 
 
  
   net.sourceforge.cobertura
   cobertura-runtime
   ${cobertura.version}
   provided
   pom
  
 


STEP 3 : Include the necessary dependencies

STEP 4 : Have a separate module for merging & generating the report out of cobertura ser files

STEP 5 : Build the whole project to get the instrumented jars & war

STEP 6 : Deploy the war and run whatever tests you want to run on the application

STEP 7 : Run the Cobertura sub module with the location of ser file and generate the reports

STEP 8 : Give all the above tasks from 4 - 6 to Jenkins


1 comment:

Unknown said...

Hello karthi,

Thanks for providing this post.

I have one question about the this execution.

##Instrument
mvn clean install -Pdo-instrumentation

##Bundle Up
cd ./cobertura-maven/Cobertura
mvn package -Pcoverage-prepare-report-bundle


##Report Generation
cd ./cobertura-maven/Cobertura/target/Cobertura-0.0.1-SNAPSHOT-coberturaReporting.dir
ant -f cobertura.xml create-html-report

1. After ran the about three steps, we need to place

a) the war file on webserver (in my case jetty)
b) cobertura.ser (which generated by third step, in merges folder)

2. Once we start the server, and ran the test cases. then stop the server. It will update a cobertura.ser file.

then again, we need to run the third step ???? Do we need to do any additional settings?

Please let me know

Thanks,
Sreedhar.