简体   繁体   English

Jenkins和Jacoco集成测试覆盖率

[英]Jenkins and Jacoco Integration Test Coverage

I just added Jacoco on my maven dependencies to run integration tests. 我刚刚在我的Maven依赖项上添加了Jacoco,以运行集成测试。 Then, I created an integration test to test my controller. 然后,我创建了一个集成测试来测试我的控制器。 For example, I tested my HTTP response codes, the headers and the response resources. 例如,我测试了HTTP响应代码,标头和响应资源。 After that, I created a profile on maven that starts an embedded tomcat. 之后,我在maven上创建了一个配置文件,该配置文件启动了嵌入式tomcat。 So, everytime I want to run my integration tests, I just put the profile on the maven goals. 因此,每次我要运行集成测试时,我都将概要放在了Maven目标上。 However, when I execute the build on Jenkins and Sonar reads the reports from Jacoco, the reports says that I have not tested my controller. 但是,当我在Jenkins上执行构建时,Sonar从Jacoco读取了报告,报告说我尚未测试我的控制器。 The question is: How I tell Jacoco that I have passed through my Controllers, Services and Repositories? 问题是:如何告诉Jacoco我已通过控制器,服务和存储库?

Thanks to all! 谢谢大家!

Are you getting any Integration Coverage, or just 0%? 您获得任何集成覆盖率,还是只有0%? It can be quite tricky to set up Integration Test Coverage using maven and Sonar. 使用maven和Sonar设置Integration Test Coverage可能非常棘手。

Check there is a jacoco file produced when the IT tests are run. 检查在运行IT测试时是否生成了jacoco文件。

Check your POM set up compared to this... 与此相比,检查您的POM设置...

<properties>
    <!-- Jacoco Properties -->
    <jacoco.version>0.7.4.201502262128</jacoco.version>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
    <sonar.jacoco.itReportPath>${project.basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.language>java</sonar.language>        
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <executions>
                <execution>
                    <id>prepare-unit-test-agent</id>
                    <configuration>
                    </configuration>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-site</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>prepare-it-test-agent</id>
                    <configuration>
                        <propertyName>jacoco.agent.argLine</propertyName>
                        <destFile>${sonar.jacoco.itReportPath}</destFile>
                        <append>true</append>
                    </configuration>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
                <argLine>${jacoco.agent.argLine}</argLine>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>    

Link to GitHub example 链接到GitHub示例

BeyondCoding.net 超越编码网

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM