Skip to content

Commit 4e73599

Browse files
Update README.md
tried to update the readme.md file with proper documentation.
1 parent 1aec92b commit 4e73599

File tree

1 file changed

+91
-15
lines changed

1 file changed

+91
-15
lines changed

README.md

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,105 @@
1-
# Testcontainers
1+
Testcontainers for Java
22

3-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.testcontainers/testcontainers/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.testcontainers/testcontainers)
3+
Testcontainers is an open-source Java library that makes it easy to write integration tests with real dependencies
4+
java.testcontainers.org
5+
. It lets you run “throwaway” Docker containers (for databases, web browsers, message brokers, etc.) during JUnit or Spock tests, without manual setup. You simply declare the test dependencies in code and Testcontainers handles starting and stopping the containers automatically
6+
testcontainers.com
7+
. This means there’s no need for fixed ports, environment configuration, or complex mocks – all you need is Docker
8+
testcontainers.com
9+
. Testcontainers works with popular JVM test frameworks (e.g. JUnit 4, JUnit 5/Jupiter, Spock)
10+
java.testcontainers.org
11+
.
12+
Key Features
413

5-
[![Netlify Status](https://api.netlify.com/api/v1/badges/189f28a2-7faa-42ff-b03c-738142079cc9/deploy-status)](https://app.netlify.com/sites/testcontainers/deploys)
14+
Real containerized dependencies: Enables using actual services (e.g. MySQL, PostgreSQL, Oracle, Redis, Kafka, etc.) in tests, started from Docker images. For example, you can run a PostgreSQL or MySQL container to test your data layer against a real database
15+
java.testcontainers.org
16+
.
617

7-
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=33816473&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=EastUs)
18+
Application integration tests: Run your application (or parts of it) with its dependencies (databases, message queues, caches) in isolated containers, ensuring tests use a clean, known environment
19+
java.testcontainers.org
20+
.
821

9-
[![Revved up by Develocity](https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.testcontainers.org/scans)
22+
UI/Acceptance tests: Supports containerized Selenium-compatible browsers (Chrome, Firefox, etc.) for UI tests, with each test getting a fresh browser instance (including optional video recording)
23+
java.testcontainers.org
24+
.
1025

11-
> Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
26+
Extensible modules: Many specialized modules are available (for databases, queues, cloud services, etc.). You can also use GenericContainer to define any Docker image as a test resource, or write custom containers. Testcontainers’ [GenericContainer] base class lets you create custom container tests as needed
27+
java.testcontainers.org
28+
.
1229

13-
![Testcontainers logo](docs/logo.png)
30+
Installation
1431

15-
# [Read the documentation here](https://java.testcontainers.org)
32+
Add the Testcontainers core library to your project’s test dependencies. For example, with Maven in pom.xml:
1633

17-
## License
34+
<dependency>
35+
<groupId>org.testcontainers</groupId>
36+
<artifactId>testcontainers</artifactId>
37+
<version>1.21.3</version>
38+
<scope>test</scope>
39+
</dependency>
1840

19-
See [LICENSE](LICENSE).
41+
java.testcontainers.org
2042

21-
## Copyright
43+
Or with Gradle (Groovy DSL):
2244

23-
Copyright (c) 2015 - 2021 Richard North and other authors.
45+
testImplementation "org.testcontainers:testcontainers:1.21.3"
2446

25-
MS SQL Server module is (c) 2017 - 2021 G DATA Software AG and other authors.
47+
Additionally, if you use JUnit 5 you should include the JUnit Jupiter integration:
2648

27-
Hashicorp Vault module is (c) 2017 - 2021 Capital One Services, LLC and other authors.
49+
testImplementation "org.testcontainers:junit-jupiter:1.21.3"
2850

29-
See [contributors](https://github.com/testcontainers/testcontainers-java/graphs/contributors) for all contributors.
51+
java.testcontainers.org
52+
53+
This pulls Testcontainers (and its transitive dependencies) from Maven Central. For managing multiple Testcontainers modules, you can also use the official Bill of Materials (testcontainers-bom) to avoid specifying versions on each dependency
54+
java.testcontainers.org
55+
.
56+
Usage Example
57+
58+
Below is a simple JUnit 5 example. We annotate the test class with @Testcontainers and declare a @Container field. Testcontainers will start the container before the tests and stop it afterward automatically:
59+
60+
@Testcontainers
61+
public class ExampleRedisTest {
62+
@Container
63+
public static GenericContainer<?> redis =
64+
new GenericContainer<>("redis:6-alpine")
65+
.withExposedPorts(6379);
66+
67+
@Test
68+
public void testRedisConnection() {
69+
String address = redis.getHost();
70+
Integer port = redis.getFirstMappedPort();
71+
// ... use the Redis container in assertions ...
72+
}
73+
}
74+
75+
This shows a JUnit 5 test that launches a Redis container for testing. (Adapted from the official quickstart guide
76+
java.testcontainers.org
77+
.) You could similarly use specific containers, e.g. PostgreSQLContainer, MySQLContainer, BrowserWebDriverContainer, etc. Testcontainers will pull the Docker image, start the container, wait until it’s ready, and then tear it down when tests complete.
78+
Contributing
79+
80+
Testcontainers is a community-driven open-source project and welcomes contributions. See the CONTRIBUTING.md file for guidelines on reporting issues or submitting pull requests. (The repository is part of the GitHub Sponsors program, and sponsor-bounties may be available on issues
81+
raw.githubusercontent.com
82+
.) You can also find contribution tips and documentation guidelines in the project docs
83+
raw.githubusercontent.com
84+
raw.githubusercontent.com
85+
.
86+
License
87+
88+
This project is licensed under the MIT License (see the LICENSE file)
89+
github.com
90+
.
91+
Copyright
92+
93+
© 2015–2021 Richard North and other authors.
94+
MS SQL Server module © 2017–2021 G DATA Software AG and other authors.
95+
HashiCorp Vault module © 2017–2021 Capital One Services, LLC and other authors.
96+
See the CONTRIBUTORS list for all contributors
97+
github.com
98+
.
99+
100+
References: Official Testcontainers documentation and GitHub repo
101+
java.testcontainers.org
102+
testcontainers.com
103+
java.testcontainers.org
104+
github.com
105+
.

0 commit comments

Comments
 (0)