如何在不创建额外测试模块的情况下使用failsafe和Junit5测试JPMS服务?

问题描述 投票:1回答:1

我有一个包含com.temp包的模块,它具有服务的接口和实现 - 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服务的集成测试?是否可以在模块外部进行检查,以便将模块检查为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();
}
java maven java-9 maven-failsafe-plugin java-module
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.