英文:
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.
<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 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<?> redis = new GenericContainer<>("redis:5.0.3-alpine")
.withExposedPorts(6379);
Or switch to the release candidate, e.g. version 1.15.0-rc2
, which supports
DockerImageName.parse("redis:5.0.3-alpine")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论