Testcontainers快速入门示例无法工作。

huangapple go评论84阅读模式
英文:

Testcontainers Quickstart Example does not work?

问题

我正在尝试 JUnit 5 Testcontainers 快速入门示例:

https://www.testcontainers.org/quickstart/junit_5_quickstart/

我使用的是 jupiter 版本 5.6.1,以及 testcontainers 版本 1.14.3。

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.6.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-params</artifactId>
    <version>5.6.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.6.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers</artifactId>
    <version>1.14.3</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>1.14.3</version>
    <scope>test</scope>
</dependency>
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@Testcontainers
public class TestcontainersDemo {
    @Container
    public GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
            .withExposedPorts(6379);
}

Eclipse IDE 报错:

The method parse(String) is undefined for the type DockerImageName

我该如何修复这个问题?

英文:

I'm trying the Junit 5 Testcontainers Quickstart Example:

https://www.testcontainers.org/quickstart/junit_5_quickstart/

I use version 5.6.1 for jupiter and version 1.14.3 for testcontainers.

&lt;dependency&gt;
    &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
    &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
    &lt;version&gt;5.6.1&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
    &lt;artifactId&gt;junit-jupiter-params&lt;/artifactId&gt;
    &lt;version&gt;5.6.1&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
    &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
    &lt;version&gt;5.6.1&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.testcontainers&lt;/groupId&gt;
    &lt;artifactId&gt;testcontainers&lt;/artifactId&gt;
    &lt;version&gt;1.14.3&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.testcontainers&lt;/groupId&gt;
    &lt;artifactId&gt;junit-jupiter&lt;/artifactId&gt;
    &lt;version&gt;1.14.3&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@Testcontainers
public class TestcontainersDemo {
	@Container
	public GenericContainer redis = new GenericContainer(DockerImageName.parse(&quot;redis:5.0.3-alpine&quot;))
			.withExposedPorts(6379);

}

Eclipse IDE is complaining

The method parse(String) is undefined for the type DockerImageName

How can I fix this?

答案1

得分: 1

对于测试容器1.14.3,只需使用以下代码部分。

@Container
public GenericContainer<?> redis = new GenericContainer<>("redis:5.0.3-alpine")
.withExposedPorts(6379);

或者切换到发布候选版本,例如版本1.15.0-rc2,它支持以下功能。

DockerImageName.parse("redis:5.0.3-alpine")
英文:

For testcontainer 1.14.3 just use.

@Container
public GenericContainer&lt;?&gt; redis = new GenericContainer&lt;&gt;(&quot;redis:5.0.3-alpine&quot;)
.withExposedPorts(6379);

Or switch to the release candidate, e.g. version 1.15.0-rc2, which supports

DockerImageName.parse(&quot;redis:5.0.3-alpine&quot;)

huangapple
  • 本文由 发表于 2020年10月5日 16:00:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/64204602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定