How to generate report for integration tests using mvn site command
Asked Answered
G

2

8

I have some Unit Tests (classes *Test.java in src/test folder, executed by Surefire Plugin) and some other Integration Tests (classes *IT.java in src/it folder, executed by Failsafe Plugin): .xml and .txt reports are correctly generated in folders target/surfire-reports and target/failsafe-reports when I run
mvn install .

Furthermore I would like to have html reports: I think that the best solution should be to use mvn site, in order to have also CSS files.
However, now only unit tests are executed, so only target/surfire-reports are generated and obviously the only html doc that is generated is about unit tests.

POM snippet below:

<build>
...
   <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      ...
   </plugin>
   <plugin>
      <artifactId>maven-failsafe-plugin</artifactId>
      ...
      <goal>integration-test</goal>
      <goal>verify</goal>
      ...
   </plugin>
   <plugin> 
      // definition of build helper maven plugin for the registration 
      // of the src/it folder
   </plugin>
...
</build>

<reporting>
  <plugins>
     <plugin>
         <groupId>org.maven.maven.plugins</groupId>
         <artifactId>maven-surefire-report-plugin</artifactId>
         <version>2.19.1</version>
     </plugin>
   </plugins>
</reporting>

Clearly, mvn site doesn't execute integration-test goal, but how can I solve?

PS: A silly solution is to run mvn site after mvn install (without a clean), but I would like to have something smarter.

Garganey answered 27/3, 2017 at 15:40 Comment(0)
A
0

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's site documentation.

  • In default lifecycle you'll find "verify" step which is the one that will run you integration tests
  • In site lifecycle, you'll have your site execution.

So the command should be :

mvn clean verify site

(always clean your workspace unless special requirements)

Maven Build Lifecycle Basics

Asiatic answered 24/6, 2021 at 13:29 Comment(0)
L
0

Use JaCoCo plugin in your pom adn just run mvn clean verify command. It is open source and very easy to implement.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

add this in your pom.xml. It will generate reports in target/site/jacoco directory. if you want to integrate it with SonarQube it is very easy to setup add few params and run command mvn sonar:sonar. for more details: https://medium.com/backend-habit/generate-codecoverage-report-with-jacoco-and-sonarqube-ed15c4045885

Larianna answered 29/6, 2021 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.