java - 如何在不创建额外测试模块的情况下使用故障保护和 Junit5 测试 JPMS 服务?

标签 java maven java-9 maven-failsafe-plugin java-module

我有一个包含包 com.temp 的模块,它具有服务的接口(interface)和实现 - ServiceInterfaceServiceImpl。我的模块信息中有:

module temp {
    exports com.temp;
    provides com.temp.ServiceInterface with com.temp.ServiceImpl;
}

这是我的 pom.xml 的一部分

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.22.0</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <skipTests>${skip.integration.tests}</skipTests>
            </configuration>
        </execution>
    </executions>
</plugin>

这是我的 TempIT

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

class TempIT {

    @Test
    void tempTest() {
      System.out.println("JDKModulePath:" + System.getProperty("jdk.module.path")); //LINE Y
       ServiceLoader<ServiceInterface> loader = ServiceLoader.load(ServiceInterface.class);
       System.out.println(loader.findFirst().get().getString());//LINE X
    }

}

LINE Y 打印:JDKModulePath:null。在 LINE X 处,我得到 java.util.NoSuchElementException: No value present

如何进行JPMS服务的集成测试?是否可以在模块外部进行操作,以便将模块作为一个整体进行检查,但无需创建额外的测试模块?

编辑1: 这些是实现和接口(interface):

package com.temp;
public class ServiceImpl implements ServiceInterface {

    @Override
    public String getString() {
        return "This is test string";
    }
}

package com.temp;
public interface ServiceInterface {

    public String getString();
}

最佳答案

这似乎是一个错误,因为故障安全不会将模块放在模块路径上。查看问题https://issues.apache.org/jira/browse/SUREFIRE-1570

关于java - 如何在不创建额外测试模块的情况下使用故障保护和 Junit5 测试 JPMS 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52314884/

相关文章:

java - 使用java将音频文件转换为文本文件

JAVA GUI按钮问题

eclipse - 我应该为 maven 使用哪个 Eclipse wtp 版本?

java - 导入 Maven 插件

java - 外部资源(JS)在 spring mvc app 中的位置

java - Java 9 中不推荐使用 Observer。我们应该使用什么来代替它?

java - Http错误响应: internal server error

java - Java 中的 RFC2898DeriveBytes 实现

Java protected 变量在枚举类型中意味着什么?

java - 分散-聚集 : combine set of Mono<List<Item>> into single Mono<List<Item>>