使用测试容器时“未找到可链接容器”

ka3*_*3ak 5 java docker testcontainers

我想使用测试容器(https://www.testcontainers.org/usage.html

于是我导入了对应的Maven依赖:

<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers</artifactId>
    <version>1.10.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>oracle-xe</artifactId>
    <version>1.10.1</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

然后我右键单击任务栏上的 docker 图标 -> 设置 -> 常规并检查该项目:

Expose daemon on tcp://localhost:2375 without TLS
Run Code Online (Sandbox Code Playgroud)

按照 testcontainers 站点上的说明设置环境变量:

DOCKER_CERT_PATH=C:\Users\username\.docker
DOCKER_HOST=https://localhost:2375
DOCKER_TLS_VERIFY=1
Run Code Online (Sandbox Code Playgroud)

并使用以下代码创建了 JUnit 测试:

@Test
public void test() {
   OracleContainer oracleXE = new OracleContainer();
...
Run Code Online (Sandbox Code Playgroud)

但是我得到了错误:

Error:(82, 27) java: cannot access org.testcontainers.containers.traits.LinkableContainer
  class file for org.testcontainers.containers.traits.LinkableContainer not found
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索了“linkablecontainer not found”和“org.testcontainers.containers.traits.LinkableContainer not found”,但没有结果。

有什么想法出了什么问题吗?

Man*_*Pap 0

与您的情况不同,但我遇到了相同的错误,而且似乎并不常见。

就我而言,当数据库的依赖项不在范围测试中但它的依赖项在范围测试中时,我遇到了相同的错误testcontainers

例如关于pom.xml

        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>mssqlserver</artifactId>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

<scope>test</scope>我忘记从中删除testcontainers,之后错误就消失了。

我猜想这个错误没有全局解决方案,但原因可能是pom.xml.