dar*_*g11 5 maven jacoco sonarqube jacoco-maven-plugin
我在我的本地机器上运行 SonarQuebe 6.2,我有 Spring Boot Java 8 项目和编写的单元测试,我想上传到 Sonar 进行静态分析和代码覆盖。
生成代码覆盖率 - 我有我的 JaCoCo HTML 报告,生成了 JUnit XML 测试文件,但我的声纳似乎错过了单元测试结果,甚至认为代码覆盖率已显示:
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.facebook4j</groupId>
<artifactId>facebook4j-core</artifactId>
<version>2.4.8</version>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我的声纳-project.properties:
sonar.projectKey=org.eventizer:EventizerServer
sonar.projectName=EventizerServer
sonar.projectVersion=1.0
sonar.log.level=DEBUG
sonar.sources=src/main/
sonar.language=java
sonar.java.source=1.8
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/classes/org/eventizer/eventizerserver/
sonar.java.test.binaries=target/test-classes/org/eventizer/eventizerserver/
sonar.tests=src/test/
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPaths=target/jacoco.exec
sonar.junit.reportPaths=target/surefire-reports/
Run Code Online (Sandbox Code Playgroud)
我正在运行这个 mvn 命令:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -Dmaven.test.failure.ignore=true
结果我得到了具有以下输出的目标目录:

为以下设置的测试类目录sonar.java.test.binaries:
为以下设置的 Surefire JUnit 测试报告目录 sonar.junit.reportPaths:
之后我正在运行sonar-scanner.bat,在一些重要的(我是这样的)输出之下:

而且我真的不知道为什么会发生这种情况,因为看起来一切都正确生成了。从昨天开始,我想我已经尝试了 StackOverflow 上的所有内容,所以请不要将其标记为重复。
这更奇怪,因为当我访问这个项目的 Coverage 指标时,我可以看到 100% 单元测试通过了:

好的,我发现了一些可能是声纳错误的东西。
基本上这个项目已经推送到Sonar很久了,基本mvn sonar:sonar配置都已经有了。所以,它甚至没有做测试结果。现在我想通过 Jenkins 运行它,所以我填写了所有必要的字段sonar-project.properties并通过Sonar-Runnernot推送mvn sonar:sonar。
执行此操作后,如您所见,单元测试质量门无缘无故地失败了。因为在我最新的屏幕截图中,您可以看到实际上单元测试通过了 100.0%。
我决定通过将projectKey属性更改为其他东西来将该分析推到一个单独的项目中,突然间一切都进展顺利。
| 归档时间: |
|
| 查看次数: |
18263 次 |
| 最近记录: |