Your most unhappy customers are your greatest source of learning.

Showing posts with label code coverage. Show all posts
Showing posts with label code coverage. Show all posts

Know about java code coverage plugins : sonar

The default Java code coverage engine for unit tests to be used must be defined in
Settings > Configuration > General Settings > Java > Code coverage plugin property.
By default the Java code coverage engine with come up with sonar is JaCoCo but Cobertura, Emma or Clover can also be used.

JaCoCo

JaCoCo is an open source and robust Java code coverage tool.
For more information, see: Comparison of Emma, Clover, Cobertura and JaCoCo.
Known limitations:
  • Some libraries complain on classes, which were instrumented by JaCoCo, so exclusions must be set:
    • Javassist (e.g. when Hibernate used) - "*_javassist_*"
    • Drools - "org.drools.*"
  • Exact number of line hits not available, because JaCoCo reports only status of line (no code, not covered, partly covered, fully covered) - see JaCoCo Coverage Counters.

Cobertura

The Sonar Cobertura plugin is based on the cobertura-maven-plugin and so can only be used to compute code coverage information on Maven projects.
This plugin has only one parameter to define the maximum amount of memory used by the java process in charge to extract all code coverage information from the Cobertura report:






jacoco code coverage with Ant - Sonar

Here is the detail for how to setup code coverage using jacoco plugin which is OOB come out with SONAR :

  1. Write sample java project called ant-jacoco-codecoverage
  2.  Project folder structure would be given as below snapshot:
  3. Under the target folder you may have to create classes & reports folders where reports folder will have one more folder called junit
  4. Write sample Java class One.java in src folder you can copy paste below code  :
    1. public class One {
        String message = "foo";
        public String foo() {
          return message;
        }
        public void uncoveredMethod() {
          System.out.println(foo());
        }
      }

Most Reading

 

Like Me & Share

Buy Websites PRchecker.info

Members

Ranks