Sunday 16 February 2020

Clover

Why code coverage is required in TFS:
  • To know how well our tests actually test our code
  • To know whether we have enough testing in place
  • To maintain the test quality over the lifecycle of a project
There are many approaches to code coverage measurement. Broadly there are three approaches, which may be used in combination:
Source code instrumentation
This approach adds instrumentation statements to the source code and compiles the code with the normal compile toolchain to produce an instrumented assembly.
Intermediate code instrumentation
Here the compiled class files are instrumented by adding new byte codes, and a new instrumented class is generated.
Runtime information collection
This approach collects information from the runtime environment as the code executes to determine coverage information

Installation and set-up

  • Add clover-maven-plugin to your parent pom of the project.
  • Add the below settings in m2/settings.xml
             
                      org.openclover
             
For example I have added like below image.

Add below in pom.xml
    
        
            org.apache.maven.plugins
            maven-compiler-plugin
            3.7.0
            
                1.8
                1.8
            
        
        
            org.apache.maven.plugins
            maven-surefire-plugin
            2.21.0
        
        
            org.openclover
            clover-maven-plugin
            4.2.1
            
                
                    main
                    verify
                    
                        instrument
                        check
                    
                
                
                    pre-site
                    
                        instrument
                    
                
            
        
    
 
    
        
            org.openclover
            clover-maven-plugin
            4.2.1
            
                true
                true
                true
            
        
    

Run below command:
mvn clean install clover2:clover
Go to pringlesxtra-service-impl/target/site/clover/intex.html file and you can see the coverage report.



Open Clover Configuration



Before you get started, add this to your .m2/settings.xml file so you can reference Clover by its short name clover.
<pluginGroups>
<pluginGroup>org.openclover</pluginGroup>
</pluginGroups>

Install Clover-for-Maven by adding it to your Maven build file (pom.xml):
  1. Set up your pom.xml by adding:
    
        
            
                org.openclover
                clover-maven-plugin
                ${clover.version}     
            
        
    
  2. After adding run below command.
    mvn clean clover:setup test clover:aggregate clover:clover
  3. Reports will be in target/site/clover directory.
  4. Open Index.htm