parent
72d50ed2f8
commit
499a29c415
@ -1,23 +0,0 @@
|
|||||||
[[howto.testcontainers]]
|
|
||||||
== Use Testcontainers for integration testing
|
|
||||||
The https://www.testcontainers.org/[Testcontainers] library provides a way to manage services running inside Docker containers.
|
|
||||||
It integrates with JUnit, allowing you to write a test class that can start up a container before any of the tests run.
|
|
||||||
Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc.
|
|
||||||
Testcontainers can be used in a Spring Boot test as follows:
|
|
||||||
|
|
||||||
[source,java,indent=0,subs="verbatim"]
|
|
||||||
----
|
|
||||||
include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java[]
|
|
||||||
----
|
|
||||||
|
|
||||||
This will start up a docker container running Neo4j (if Docker is running locally) before any of the tests are run.
|
|
||||||
In most cases, you will need to configure the application using details from the running container, such as container IP or port.
|
|
||||||
|
|
||||||
This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment.
|
|
||||||
|
|
||||||
[source,java,indent=0,subs="verbatim"]
|
|
||||||
----
|
|
||||||
include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java[]
|
|
||||||
----
|
|
||||||
|
|
||||||
The above configuration allows Neo4j-related beans in the application to communicate with Neo4j running inside the Testcontainers-managed Docker container.
|
|
Loading…
Reference in New Issue