{"id":77191,"date":"2018-05-23T16:00:37","date_gmt":"2018-05-23T13:00:37","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=77191"},"modified":"2018-05-23T11:11:22","modified_gmt":"2018-05-23T08:11:22","slug":"testcontainers-and-spring-boot","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html","title":{"rendered":"TestContainers and Spring Boot"},"content":{"rendered":"<p><a href=\"https:\/\/www.testcontainers.org\/\">TestContainers<\/a> is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very useful for integration testing of applications against real databases and any other resource for which a docker image is available.<\/p>\n<p>My objective is to demonstrate a sample test for a JPA based Spring Boot Application using TestContainers. The sample is based on <a href=\"https:\/\/github.com\/testcontainers\/testcontainers-java-examples\/tree\/master\/spring-boot\">an example at the TestContainer github repo<\/a>.<\/p>\n<h2>Sample App<\/h2>\n<p>The Spring Boot based application is straightforward &#8211; It is a <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/#boot-features-jpa-and-spring-data\">Spring Data JPA<\/a> based application with the web layer written using <a href=\"https:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/web-reactive.html\">Spring Web Flux<\/a>. The entire sample is available at my <a href=\"https:\/\/github.com\/bijukunjummen\/cities\">github repo<\/a> and it may be easier to just follow the code directly there.<\/p>\n<p>The City entity being persisted looks like this (using <a href=\"https:\/\/kotlinlang.org\/\">Kotlin<\/a>):<\/p>\n<pre class=\"brush:java\">import javax.persistence.Entity\r\nimport javax.persistence.GeneratedValue\r\nimport javax.persistence.Id\r\n\r\n@Entity\r\ndata class City(\r\n        @Id @GeneratedValue var id: Long? = null,\r\n        val name: String,\r\n        val country: String,\r\n        val pop: Long\r\n) {\r\n    constructor() : this(id = null, name = \"\", country = \"\", pop = 0L)\r\n}<\/pre>\n<p>All that is needed to provide a repository to manage this entity is the following interface, thanks to the excellent <a href=\"https:\/\/projects.spring.io\/spring-data-jpa\/\">Spring Data JPA<\/a> project:<\/p>\n<pre class=\" brush:java\">import org.springframework.data.jpa.repository.JpaRepository\r\nimport samples.geo.domain.City\r\n\r\ninterface CityRepo: JpaRepository&lt;City, Long&gt;<\/pre>\n<p>I will not cover the web layer here as it is not relevant to the discussion.<\/p>\n<h2>Testing the Repository<\/h2>\n<p>Spring Boot provides a feature called the <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/#boot-features-testing-spring-boot-applications-testing-autoconfigured-tests\">Slice tests<\/a> which is a neat way to test different horizontal slices of the application. A test for the CityRepo repository looks like this:<\/p>\n<pre class=\"brush:java\">import org.junit.Test;\r\nimport org.junit.runner.RunWith;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;\r\nimport org.springframework.test.context.junit4.SpringRunner;\r\nimport samples.geo.domain.City;\r\nimport samples.geo.repo.CityRepo;\r\n\r\nimport static org.assertj.core.api.Assertions.assertThat;\r\n\r\n@RunWith(SpringRunner.class)\r\n@DataJpaTest\r\npublic class CitiesWithEmbeddedDbTest {\r\n\r\n    @Autowired\r\n    private CityRepo cityRepo;\r\n\r\n    @Test\r\n    public void testWithDb() {\r\n        City city1 = cityRepo.save(new City(null, \"city1\", \"USA\", 20000L));\r\n        City city2 = cityRepo.save(new City(null, \"city2\", \"USA\", 40000L));\r\n\r\n        assertThat(city1)\r\n                .matches(c -&gt; c.getId() != null &amp;&amp; c.getName() == \"city1\" &amp;&amp; c.getPop() == 20000L);\r\n\r\n        assertThat(city2)\r\n                .matches(c -&gt; c.getId() != null &amp;&amp; c.getName() == \"city2\" &amp;&amp; c.getPop() == 40000L);\r\n\r\n        assertThat(cityRepo.findAll()).containsExactly(city1, city2);\r\n    }\r\n\r\n}<\/pre>\n<p>The <a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/#boot-features-testing-spring-boot-applications-testing-autoconfigured-jpa-test\">&#8220;@DataJpaTest&#8221;<\/a> annotation starts up an embedded h2 databases, configures JPA and loads up any Spring Data JPA repositories(CityRepo in this instance).<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>This kind of a test works well, considering that JPA provides the database abstraction and if JPA is used correctly the code should be portable across any supported databases. However, assuming that this application is expected to be run against a <a href=\"https:\/\/www.postgresql.org\/\">PostgreSQL<\/a> in production, ideally, there would be some level of integration testing done against the database, which is where TestContainer fits in. It provides a way to boot up PostgreSQL as a docker container.<\/p>\n<h2>TestContainers<\/h2>\n<p>The same repository test using <a href=\"https:\/\/www.testcontainers.org\/usage\/database_containers.html\">TestContainers<\/a> looks like this:<\/p>\n<pre class=\"brush:java\">import org.junit.ClassRule;\r\nimport org.junit.Test;\r\nimport org.junit.runner.RunWith;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;\r\nimport org.springframework.boot.test.util.TestPropertyValues;\r\nimport org.springframework.context.ApplicationContextInitializer;\r\nimport org.springframework.context.ConfigurableApplicationContext;\r\nimport org.springframework.test.context.ContextConfiguration;\r\nimport org.springframework.test.context.junit4.SpringRunner;\r\nimport org.testcontainers.containers.PostgreSQLContainer;\r\nimport samples.geo.domain.City;\r\nimport samples.geo.repo.CityRepo;\r\n\r\nimport java.time.Duration;\r\n\r\nimport static org.assertj.core.api.Assertions.assertThat;\r\n\r\n@RunWith(SpringRunner.class)\r\n@DataJpaTest\r\n@ContextConfiguration(initializers = {CitiesWithPostgresContainerTest.Initializer.class})\r\npublic class CitiesWithPostgresContainerTest {\r\n\r\n    @ClassRule\r\n    public static PostgreSQLContainer postgreSQLContainer =\r\n            (PostgreSQLContainer) new PostgreSQLContainer(\"postgres:10.4\")\r\n                    .withDatabaseName(\"sampledb\")\r\n                    .withUsername(\"sampleuser\")\r\n                    .withPassword(\"samplepwd\")\r\n                    .withStartupTimeout(Duration.ofSeconds(600));\r\n\r\n    @Autowired\r\n    private CityRepo cityRepo;\r\n\r\n    @Test\r\n    public void testWithDb() {\r\n        City city1 = cityRepo.save(new City(null, \"city1\", \"USA\", 20000L));\r\n        City city2 = cityRepo.save(new City(null, \"city2\", \"USA\", 40000L));\r\n\r\n        assertThat(city1)\r\n                .matches(c -&gt; c.getId() != null &amp;&amp; c.getName() == \"city1\" &amp;&amp; c.getPop() == 20000L);\r\n\r\n        assertThat(city2)\r\n                .matches(c -&gt; c.getId() != null &amp;&amp; c.getName() == \"city2\" &amp;&amp; c.getPop() == 40000L);\r\n\r\n        assertThat(cityRepo.findAll()).containsExactly(city1, city2);\r\n    }\r\n\r\n    static class Initializer\r\n            implements ApplicationContextInitializer&lt;ConfigurableApplicationContext&gt; {\r\n        public void initialize(ConfigurableApplicationContext configurableApplicationContext) {\r\n            TestPropertyValues.of(\r\n                    \"spring.datasource.url=\" + postgreSQLContainer.getJdbcUrl(),\r\n                    \"spring.datasource.username=\" + postgreSQLContainer.getUsername(),\r\n                    \"spring.datasource.password=\" + postgreSQLContainer.getPassword()\r\n            ).applyTo(configurableApplicationContext.getEnvironment());\r\n        }\r\n    }\r\n}<\/pre>\n<p>The core of the code looks same as the previous test, but the repository here is being tested against a real PostgreSQL database here. To go into a little more detail &#8211;<\/p>\n<p>A PostgreSQL container is being started up using a <a href=\"https:\/\/junit.org\/junit4\/javadoc\/4.12\/org\/junit\/ClassRule.html\">JUnit Class Rule<\/a> which gets triggered before any of the tests are run. This dependency is being pulled in using a gradle dependency of the following type:<\/p>\n<pre class=\"brush:java\">testCompile(\"org.testcontainers:postgresql:1.7.3\")<\/pre>\n<p>The class rule starts up a PostgreSQL docker container(postgres:10.4) and configures a database, and credentials for the database. Now from Spring Boot&#8217;s perspective, these details need to be passed on the application as properties BEFORE Spring starts creating a test context for the test to run in, and this is done for the test using an <a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/context\/ApplicationContextInitializer.html\">ApplicationContextInitializer<\/a>, this is invoked by Spring very early in the lifecycle of a Spring Context.<\/p>\n<p>The custom ApplicationContextInitializer which sets the database name, url and user credentials is hooked up to the test using this code:<\/p>\n<pre class=\"brush:java\">...\r\nimport org.springframework.test.context.ContextConfiguration;\r\nimport org.springframework.test.context.junit4.SpringRunner;\r\n...\r\n\r\n@RunWith(SpringRunner.class)\r\n@DataJpaTest\r\n@ContextConfiguration(initializers = {CitiesWithPostgresContainerTest.Initializer.class})\r\npublic class CitiesWithPostgresContainerTest {\r\n...<\/pre>\n<p>With this boiler plate set up in place TestContainer and Spring Boot slice test will take over running of the test. More importantly TestContainers also takes care of tear down, the JUnit Class Rule ensures that once the test is complete the containers are stopped and removed.<\/p>\n<h2>Conclusion<\/h2>\n<p>This was a whirlwind tour of TestContainers, there is far more to TestContainers than what I have covered here but I hope this provides a taste for what is feasible using this excellent library and how to configure it with Spring Boot. This sample is available at my <a href=\"https:\/\/github.com\/bijukunjummen\/cities\/blob\/master\/src\/test\/java\/samples\/geo\/tc\/CitiesWithPostgresContainerTest.javahttp:\/\/\">github repo<\/a><\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Biju Kunjummen, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/www.java-allandsundry.com\/2018\/05\/testcontainers-and-spring-boot.html\" target=\"_blank\" rel=\"noopener\">TestContainers and Spring Boot<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very useful for integration testing of applications against real databases and any other resource for which a docker image is available. My objective is to demonstrate a sample test for &hellip;<\/p>\n","protected":false},"author":236,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[936,854,1752],"class_list":["post-77191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-docker","tag-spring-boot","tag-webflux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TestContainers and Spring Boot - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TestContainers and Spring Boot - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-23T13:00:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Biju Kunjummen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Biju Kunjummen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html\"},\"author\":{\"name\":\"Biju Kunjummen\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\"},\"headline\":\"TestContainers and Spring Boot\",\"datePublished\":\"2018-05-23T13:00:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html\"},\"wordCount\":613,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Docker\",\"Spring Boot\",\"webflux\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html\",\"name\":\"TestContainers and Spring Boot - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2018-05-23T13:00:37+00:00\",\"description\":\"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/05\\\/testcontainers-and-spring-boot.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"TestContainers and Spring Boot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\",\"name\":\"Biju Kunjummen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"caption\":\"Biju Kunjummen\"},\"sameAs\":[\"http:\\\/\\\/biju-allandsundry.blogspot.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Biju-Kunjummen\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TestContainers and Spring Boot - Java Code Geeks","description":"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html","og_locale":"en_US","og_type":"article","og_title":"TestContainers and Spring Boot - Java Code Geeks","og_description":"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very","og_url":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-05-23T13:00:37+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Biju Kunjummen","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Biju Kunjummen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html"},"author":{"name":"Biju Kunjummen","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5"},"headline":"TestContainers and Spring Boot","datePublished":"2018-05-23T13:00:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html"},"wordCount":613,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Docker","Spring Boot","webflux"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html","url":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html","name":"TestContainers and Spring Boot - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2018-05-23T13:00:37+00:00","description":"TestContainers is just awesome! It provides a very convenient way to start up and CLEANLY tear down docker containers in JUnit tests. This feature is very","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/05\/testcontainers-and-spring-boot.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"TestContainers and Spring Boot"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5","name":"Biju Kunjummen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","caption":"Biju Kunjummen"},"sameAs":["http:\/\/biju-allandsundry.blogspot.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/Biju-Kunjummen"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/77191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=77191"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/77191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=77191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=77191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=77191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}