Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Java

    For java there are different plugins/properties that must be included in the pom.xml to execute the tests and record the coverage during the execution

    Maven Properties

    Code Block
    languagexml
    <properties>
    ...
                    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
                    <sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
                    <sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco.exec</sonar.jacoco.reportPath>
                    <sonar.jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it.exec</sonar.jacoco.itReportPath>
                    <sonar.jacoco.reportMissing.force.zero>true</sonar.jacoco.reportMissing.force.zero>
                    <sonar.projectVersion>${project.version}</sonar.projectVersion>
                    <!-- Enable language to disable other language analysis -->
                    <sonar.language>java</sonar.language>
                    <sonar.exclusions>src/main/resources/**</sonar.exclusions>
    ...
    </properties>

    Surefire (Unit tests)

    This one is used to execute the unit tests, various config are available depending of the project need (https://maven.apache.org/surefire/maven-surefire-plugin/index.html)

    Code Block
    languagexml
    <plugin>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-surefire-plugin</artifactId>
    	<version>X.XX.X</version>
    	<configuration>
    		<forkCount>1</forkCount>
    		<reuseForks>true</reuseForks>
    		<useSystemClassLoader>false</useSystemClassLoader>
    	</configuration>
    </plugin>

    Failsafe (Integration tests)

    This one is used to execute the integration tests, various config are available depending of the project need (https://maven.apache.org/surefire/maven-failsafe-plugin/index.html)

    Code Block
    languagexml
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>X.XX.X</version>
        <executions>
          <execution>
             <id>integration-tests</id>
             <goals>
               <goal>integration-test</goal>
               <goal>verify</goal>
             </goals>
             <configuration>
               <additionalClasspathElements>
                  <additionalClasspathElement>${project.build.directory}/classes</additionalClasspathElement>
               </additionalClasspathElements>
               <includes>
                 <include>**/*ItCase.java</include>
               </includes>
               <forkCount>1</forkCount>
               <reuseForks>false</reuseForks>
               <useSystemClassLoader>false</useSystemClassLoader>
             </configuration>
          </execution>
        </executions>
    </plugin>

    Jacoco

    This one is used to record the coverage of the unit tests and integration tests, also a result merge for the developer IDE (https://www.eclemma.org/jacoco/trunk/doc/maven.html)

    Code Block
    languagexml
    <plugin>
                                    <groupId>org.jacoco</groupId>
                                    <artifactId>jacoco-maven-plugin</artifactId>
                                    <version>0.8.2</version>
                                    <configuration>
                                            <dumpOnExit>true</dumpOnExit>
                                            <includes>
                                                    <include>org.onap.*</include>
                                            </includes>
                                            <propertyName>surefireArgLine</propertyName>
                                    </configuration>
                                    <executions>
                                            <execution>
                                                    <id>pre-unit-test</id>
                                                    <goals>
                                                            <goal>prepare-agent</goal>
                                                    </goals>
                                                    <configuration>
                                                            <destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
                                                            <!-- <append>true</append> -->
                                                    </configuration>
                                            </execution>
                                            <execution>
                                                    <id>pre-integration-test</id>
                                                    <phase>pre-integration-test</phase>
                                                    <goals>
                                                            <goal>prepare-agent</goal>
                                                    </goals>
                                                    <configuration>
                                                            <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
                                                            <!-- <append>true</append> -->
                                                    </configuration>
                                            </execution>
                                            <execution>
                                                    <goals>
                                                            <goal>merge</goal>
                                                    </goals>
                                                    <phase>post-integration-test</phase>
                                                    <configuration>
                                                            <fileSets>
                                                                    <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
                                                                            <directory>${project.build.directory}/coverage-reports</directory>
                                                                            <includes>
                                                                                    <include>*.exec</include>
                                                                            </includes>
                                                                    </fileSet>
                                                            </fileSets>
                                                            <destFile>${project.build.directory}/jacoco-dev.exec</destFile>
                                                    </configuration>
                                            </execution>
                                    </executions>
    </plugin>

    Note that for the integration tests, it could more complex than the following Jacoco plugin usage, if .

    If it's a remote server or anything else the jacoco agent must be provided to the running JVM to do the coverage recording (https://www.eclemma.org/jacoco/trunk/doc/agent.html)

    Maven properties

    Javascript

    ), then brought back to build folder.

    Docker Plugin (Integration tests)

    This plugin can be used to start containers before doing the integration tests. The following example starts Mariadb and Python before the integration tests phase.

    Code Block
    languagexml
    <plugin>
                                    <groupId>io.fabric8</groupId>
                                    <artifactId>docker-maven-plugin</artifactId>
                                    <version>0.26.0</version>
                                    <configuration>
                                            <verbose>true</verbose>
                                            <apiVersion>1.23</apiVersion>
                                            <images>
                                                    <image>
                                                            <name>library/mariadb:10.1.11</name>
                                                            <alias>mariadb</alias>
                                                            <run>
                                                                    <env>
                                                                            <MYSQL_ROOT_PASSWORD>secret</MYSQL_ROOT_PASSWORD>
                                                                    </env>
                                                                    <hostname>mariadb</hostname>
                                                                    <volumes>
                                                                            <bind>
                                                                                    <volume>${project.basedir}/extra/sql/:/docker-entrypoint-initdb.d</volume>
                                                                                    <volume>${project.basedir}/extra/docker/mariadb/conf1:/etc/mysql/conf.d</volume>
                                                                            </bind>
                                                                    </volumes>
                                                                    <wait>
                                                                            <log>socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution</log>
                                                                            <time>600000</time>
                                                                    </wait>
                                                                    <ports>
                                                                            <port>${docker.mariadb.port.host}:3306</port>
                                                                    </ports>
                                                            </run>
                                                    </image>
                                                    <image>
                                                            <name>library/python:2-slim</name>
                                                            <alias>python</alias>
                                                            <run>
                                                                    <hostname>python</hostname>
                                                                    <volumes>
                                                                            <bind>
                                                                                    <volume>${project.basedir}/src/test/resources/http-cache/:/usr/src/http-cache-app</volume>
                                                                                    <volume>${project.basedir}/src/test/resources/http-cache/example/:/usr/src/http-cache-app/data-cache</volume>
                                                                            </bind>
                                                                    </volumes>
                                                                    <wait>
                                                                            <tcp>
                                                                                    <ports>
                                                                                            <port>8080</port>
                                                                                    </ports>
                                                                                    <mode>direct</mode>
                                                                            </tcp>
                                                                            <time>120000</time>
                                                                    </wait>
                                                                    <ports>
                                                                            <port>${docker.http-cache.port.host}:8080</port>
                                                                    </ports>
                                                                    <workingDir>/usr/src/http-cache-app</workingDir>
                                                                    <cmd>
                                                                            <shell>./start_http_cache.sh ${python.http.proxy.param} --python_proxyaddress=localhost:${docker.http-cache.port.host}</shell>
                                                                    </cmd>
                                                            </run>
                                                   </image>                                      
                                    </configuration>
                                    <executions>
                                            <execution>
                                                    <id>docker-start-for-it</id>
                                                    <phase>pre-integration-test</phase>
                                                    <goals>
                                                            <goal>start</goal>
                                                    </goals>
                                            </execution>
                                            <execution>
                                                    <id>docker-stop-for-it</id>
                                                    <phase>post-integration-test</phase>
                                                    <goals>
                                                            <goal>stop</goal>
                                                    </goals>
                                            </execution>
                                    </executions>
    </plugin>
  • Javascript

    Maven properties

    Code Block
    languagexml
                    <sonar.javascript.lcov.reportPaths>${project.build.directory}/clamp-ui/coverage/lcov.info</sonar.javascript.lcov.reportPaths>
                    <sonar.projectVersion>${project.version}</sonar.projectVersion>
                    <sonar.sources>src/main,${project.build.directory}/clamp-ui/designer</sonar.sources>
                    <sonar.exclusions>src/main/resources/**,**/clamp-ui/designer/lib/*</sonar.exclusions>
    
    
    
  • Python

    Section TBD