NetBeans,Jacoco和Optional.orElseThrow()

时间:2016-08-11 09:48:48

标签: java netbeans jacoco

我使用NetBeans和JaCoCo,在我的项目的Maven POM中进行配置:

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.7.201606060606</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

对于此代码:

public String showName(Optional<String> maybeName) {
    return maybeName.orElseThrow(() -> new RuntimeException("Missing name"));
}

此测试:

@Test
public void testShowName() {
    String actual = foo.showName(Optional.of("John"));
    assertEquals("John", actual);
}

...然后NetBeans代码覆盖率报告显示100%的覆盖率。这是不正确的,因为我没有运用maybeName == Optional.empty()并抛出异常的情况。

在Eclipse中使用EclEmma,我看到了部分覆盖,正如预期的那样。

我需要给JaCoCo一些进一步的配置吗?

0 个答案:

没有答案