有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用failsafe和Junit5测试JPMS服务,而无需创建额外的测试模块?

我有一个包含包com.temp的模块,它有接口和th服务的实现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>

这是我的临时工

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
    }

}

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

如何对JPMS服务进行集成测试?是否可以在模块之外执行此操作,以便将模块检查为one whole,但不创建额外的测试模块

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

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();
}

共 (1) 个答案