Testcontainers Quickstart Example does not work?

1.4k views Asked by At

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

There are 1 answers

0
jschnasse On BEST ANSWER

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")