1

我在 sonarcloude 中获得了 97.9 % 的代码覆盖率,我想让它达到 100%。错误显示我的 SpringProjectMainApplication.java 没有被测试覆盖。

主要课程是:

**@SpringBootApplication
public class SpringProjectMainApplication {
    @Generated(value = { "" })
    public static void main(String... args) {
            SpringApplication.run(SpringProjectMainApplication.class, args);
        }
    }**

测试类是

**@SpringBootTest
public class SpringProjectApplicationTests {
    @Test
    public void contextLoads() {
       }
}**

声纳云错误是:

声纳云 声纳 云错误

我的 Pom 文件具有以下配置:

</sonar.sources>
        <sonar.issue.ignore.multicriteria>e11, e12</sonar.issue.ignore.multicriteria>
        <!-- Disable rule for "Add at least one assertion for the contextLoads 
            test case" -->
        <sonar.issue.ignore.multicriteria.e11.ruleKey>squid:S2699</sonar.issue.ignore.multicriteria.e11.ruleKey>
        <sonar.issue.ignore.multicriteria.e11.resourceKey>**/SpringProjectApplicationTests.java</sonar.issue.ignore.multicriteria.e11.resourceKey>
        <!-- Disable rule for if cases in methods equals -->
        <sonar.issue.ignore.multicriteria.e12.ruleKey>squid:S3776</sonar.issue.ignore.multicriteria.e12.ruleKey>
        <sonar.issue.ignore.multicriteria.e12.resourceKey>**/model/**</sonar.issue.ignore.multicriteria.e12.resourceKey>
         <sonar.issue.ignore.multicriteria.e13.resourceKey>**/SpringProjectApplicationTests.java</sonar.issue.ignore.multicriteria.e13.resourceKey>
         <sonar.issue.ignore.multicriteria.e13.resourceKey>**/SpringProjectMainApplication.java</sonar.issue.ignore.multicriteria.e13.resourceKey>
         <skip.unit-tests>false</skip.unit-tests>
        <skipITs>false</skipITs>
        </properties>


<groupId>org.sonarsource.scanner.maven</groupId>
                            <artifactId>sonar-maven-plugin</artifactId>
                            <version>3.6.0.1398</version>
                        </plugin>
                    </plugins>
                </pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.4</version>
                        <configuration>
                            <excludes>
                                <exclude>**/model/**</exclude>
                                <exclude>**/SpringProjectApplication.*</exclude>
                                <exclude>**/config/**</exclude>
                                <exclude>
  **/src/it/java/SpringProjectApplicationTests.java
                                 </exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <!-- binds by default to the phase "initialize" -->
                                    <goal>prepare-agent</goal>
                                    <!-- binds by default to the phase "verify" -->
                                    <goal>report</goal>
4

1 回答 1

0

它看起来像您的配置中的错字。它应该是“SpringProjectMainApplication”而不是“SpringProjectApplication”。

<excludes>
    ....
    <exclude>**/SpringProjectMainApplication.class</exclude>
    ....
</excludes>
于 2020-06-28T12:45:07.557 回答