$ git clone https://github.com/foo/bar.git
$ cd bar
$ ./gradlew build
For example:
"Tests which interact with external systems/dependencies"
GenericContainer redis =
new GenericContainer(
"redis:5.0.3-alpine"
).withExposedPorts(6379);
redis.start();
// test my stuff
redis.stop();
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.16.2</version>
<scope>test</scope>
</dependency>
testImplementation "org.testcontainers:testcontainers:1.16.2"
@whichrich
@Rule
public GenericContainer redis =
new GenericContainer(
"redis:5.0.3-alpine"
).withExposedPorts(6379);
@Testcontainers
class TestContainersClassIT extends Specification {
@Shared
GenericContainer redis =
new GenericContainer("redis:5.0.3-alpine")
.withExposedPorts(6379)
// tests here
}
@Testcontainers
class SomeTest {
@Container
public GenericContainer redis =
new GenericContainer(
"redis:5.0.3-alpine"
).withExposedPorts(6379);
// test methods
}
abstract class AbstractContainerBaseTest {
static final MySQLContainer MY_SQL_CONTAINER;
static {
MY_SQL_CONTAINER = new MySQLContainer();
MY_SQL_CONTAINER.start();
}
}
class FirstTest extends AbstractContainerBaseTest {
@Test
void someTestMethod() {
String url = MY_SQL_CONTAINER.getJdbcUrl();
// create a connection and run test as normal
}
}
version: "3"
services:
vote:
image: vote-frontend
command: python app.py
volumes:
- ./vote:/app
ports:
- "5000:80"
redis:
image: redis:alpine
ports: ["6379"]
worker:
image: worker
db:
image: postgres:9.4
result:
image: result-frontend
command: nodemon --debug server.js
volumes:
- ./result:/app
ports:
- "5001:80"
- "5858:5858"