3r1co / jacoco

A sample project to demonstrate the usage of JaCaCo for Integration Tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code Coverage with TomEE, JaCoCo and SonarQube

In this little example I present you how to easily run code coverage analysis for integration tests.

How To Run

  1. Compile the project with Maven first, as the class files need to be available for the Code Coverage Analysis:

    mvn clean package
    
  2. Download the Jacoco Agent from here.

  3. Place it in the root of the repository (as it is linked in the docker-compose.yml)

  4. Start the docker-compose stack.

    docker-compose up -d
    
  5. Connect to the maven container and change to /app:

    docker exec -it jacoco_maven_1 bash
    bash-4.3# cd /app
    
  6. Fetch the JaCoCo Dump:

    mvn jacoco:dump -Djacoco.address=app
    
  7. Run the SonarQube Analysis:

    mvn sonar:sonar -Dsonar.host.url=http://sonar:9000
    
  8. Access the SonarQube Analysis under http://localhost:9000 and see the coverage report. It should say 0% of your code is covered.

  9. Access the sample application under http://localhost:8888/jacoco-example. Do some math calculations to see the analysis work.

  10. Fetch the JaCoCo Dump again:

    mvn jacoco:dump -Djacoco.address=app
    
  11. Run the SonarQube Analysis again:

    mvn sonar:sonar -Dsonar.host.url=http://sonar:9000
    
  12. Access the SonarQube Analysis under http://localhost:9000 and see the coverage report. You should see 85.7% of Code Coverage.

About

A sample project to demonstrate the usage of JaCaCo for Integration Tests


Languages

Language:Java 54.1%Language:HTML 45.9%