$ git clone https://github.com/foo/bar.git
$ cd bar
$ ./gradlew build
For example:
"Tests which interact with external systems/dependencies"
"I use the term integrated test to mean any test whose result (pass or fail) depends on the correctness of the implementation of more than one piece of non-trivial behavior." - J.B. Rainsberger
"A test that will pass or fail based on the correctness of another system." - Spotify
For example:
# simple hello world
docker container run hello-world
# we can run applications and expose ports
docker container run -ti -p 8080:80 httpd
curl localhost:80
# containers are ephemeral
docker container run -ti busybox
> echo foo > bar.txt
> ls -la
docker container run -ti busybox
# there are different versions (tags) of images
docker container run --rm ubuntu:18.04 cat /etc/os-release
docker container run --rm ubuntu:19.10 cat /etc/os-release
FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/
docker build -t myname:mytag .
docker container run -ti -v /home/myuser:/home/dockeruser:ro ubuntu:latest
docker container run -v postgres_data:/var/lib/postgresql/data postgres
docker volume ls
docker volume inspect postgres_data
# create a Docker network
docker network create my-network
# start Apache webserver attached to this network
docker container run -itd --network=my-network --network-alias=apache httpd
# start empty Ubuntu container and interact with Apache container
docker container run -it --network=my-network ubuntu
> apt update && apt install -y curl
> curl apache
version: '2'
services:
apache:
image: httpd
ports:
- '80:80'
GenericContainer redis =
new GenericContainer("redis:3.0.2")
.withExposedPorts(6379);
redis.start();
// test my stuff
redis.stop();
// Set up a redis container
@ClassRule
public static GenericContainer redis =
new GenericContainer("redis:3.0.2")
.withExposedPorts(6379);
@Testcontainers
class TestContainersClassIT extends Specification {
@Shared
GenericContainer genericContainer =
new GenericContainer("postgres:latest")
.withExposedPorts(5432)
.withEnv([
POSTGRES_USER: "foo"
POSTGRES_PASSWORD: "secret"
])
}
@Testcontainers
class SomeTest {
@Container
private MySQLContainer mySQLContainer = new MySQLContainer();
@Test
void someTestMethod() {
String url = mySQLContainer.getJdbcUrl();
// create a connection and run test as normal
}
}
driver.get("http://www.google.com");
WebElement search = driver.findElement(By.name("q"));
search.sendKeys("testcontainers");
search.submit();
List<WebElement> results = new WebDriverWait(driver, 15)
.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#search h3")));
assertTrue("the word 'testcontainers' appears in search results",
results.stream()
.anyMatch(el -> el.getText().contains("testcontainers")));
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"
private GenericContainer myContainer = new GenericContainer("myImage:42.23") {{
withExposedPorts(4711);
if (System.getenv().get("INSIDE_CI") == null) {
org.testcontainers.Testcontainers.exposeHostPorts(8080);
}
}};
TODO: add Safe Harbor Statement here