junit5测试覆盖率为0%

rwqw0loc  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(441)

我在intellij idea有一个maven项目。我的pom包含几个依赖项。下面是pom.xml的摘要。我尝试实现junit5,为此我添加了2个依赖项。

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myapp</groupId>
    <artifactId>app-sharepoint</artifactId>
    <version>2.0.0-SNAPSHOT</version>
    <name>SharePoint App</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.jupyter.version>5.7.2</junit.jupyter.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>msal4j</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph</artifactId>
            <version>3.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph-auth</artifactId>
            <version>0.3.0</version>
        </dependency>
        ...
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.jupyter.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupyter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.11.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven
                defaults (may be moved to parent pom) -->
            <plugins>
                ...
                <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <dependencies>
                        <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-surefire-provider -->
                        <dependency>
                            <groupId>org.junit.platform</groupId>
                            <artifactId>junit-platform-surefire-provider</artifactId>
                            <version>1.3.2</version>
                            <scope>test</scope>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

我试图实现测试方法,到目前为止,它是有效的。下面是我实施的一个基本测试:

public class AuthenticationManagerTest {

    @Test
    void getAccessTokenByClientCredentialGrant_invalidUrlMissingSegments() throws MalformedURLException {
        authority = "https://somestring";

        Assertions.assertThrows(IllegalArgumentException.class, () ->
                    // ConfidentialClientApplication app =
                    ConfidentialClientApplication.builder(
                            clientId,
                            ClientCredentialFactory.createFromSecret(clientSecret))
                            .authority(authority)
                            .build(),
            "Authority Uri should not have empty path segments"
        );
    }
    ....
}

在尝试使用覆盖率运行它时,我注意到覆盖的代码是0%。有什么东西不见了吗?

我还注意到,当我运行所有测试时,我的pojo类(我根本没有实现任何测试)正在确认20%的覆盖率。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题