{"id":25641950,"url":"https://github.com/paulbares/spring-testcontainer","last_synced_at":"2026-05-04T18:39:12.122Z","repository":{"id":57736676,"uuid":"317123911","full_name":"paulbares/spring-testcontainer","owner":"paulbares","description":"spring-testcontainer provides integration between the Spring (Data JPA) testing framework and Testcontainer library","archived":false,"fork":false,"pushed_at":"2023-09-13T06:03:13.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T23:05:16.095Z","etag":null,"topics":["container","spring","spring-boot","spring-jpa","testcontainers"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulbares.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-11-30T05:50:47.000Z","updated_at":"2023-09-13T06:03:14.000Z","dependencies_parsed_at":"2022-08-24T14:57:21.813Z","dependency_job_id":"9eabd87e-45e0-4c62-b9f9-98a30a8b6a73","html_url":"https://github.com/paulbares/spring-testcontainer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulbares%2Fspring-testcontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulbares%2Fspring-testcontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulbares%2Fspring-testcontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulbares%2Fspring-testcontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulbares","download_url":"https://codeload.github.com/paulbares/spring-testcontainer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271532,"owners_count":19774859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["container","spring","spring-boot","spring-jpa","testcontainers"],"created_at":"2025-02-23T05:16:36.180Z","updated_at":"2026-05-04T18:39:07.100Z","avatar_url":"https://github.com/paulbares.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\nspring-testcontainer provides integration between the Spring (Data JPA) testing framework and Testcontainer library to \neasily test your application with different containerized database instances. \n\n# Configuration\nThe simplest way to start is to use the annotation `@SpringContainerTestDatabase` on your test class and add a static \ncontainer attribute that exposes a JDBC connection:\n```java\n@Container\nstatic MySQLContainer container = new MySQLContainer(\"mysql\");\n```\n\nThe lifecycle of the container is managed by the Testcontainer library itself. \n\nEdit or create the file `spring.factories` to add:\n```\norg.springframework.test.context.ContextCustomizerFactory=\\\nme.paulbares.InjectableContextCustomizerFactory\n```\n\nThe `InjectableContextCustomizerFactory` is responsible to set the appropriate jdbc properties in the Spring context. \n\nDon't forget to add as dependencies the Testcontainers library of the db you want to use and the associated JDBC driver library, \nfor instance for MySQL:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.testcontainers\u003c/groupId\u003e\n    \u003cartifactId\u003emysql\u003c/artifactId\u003e\n    \u003cversion\u003e1.19.0\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\nDriver dependency:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003emysql\u003c/groupId\u003e\n    \u003cartifactId\u003emysql-connector-java\u003c/artifactId\u003e\n    \u003cversion\u003e8.0.33\u003c/version\u003e\n\u003c/dependency\u003e\n```\nIf you want to customize the properties datasource, you can extend and override `JdbcDbContainerContextCustomizer#getProperties`.\n\n# Example\n\n```java\n@Transactional\n@SpringContainerTestDatabase\nclass TestMySQL {\n\n  @Container\n  static MySQLContainer container = new MySQLContainer(\"mysql\");\n\n  @Autowired\n  CustomerRepository customerRepository;\n\n  @Test\n  void test() {\n    Customer c = new Customer();\n    c.setFirstname(\"admin\");\n    c.setLastname(\"admin\");\n    this.customerRepository.save(c);\n    Assertions.assertEquals(1, this.customerRepository.findAll().size()); // Whatever...\n  }\n}\n```\n# Maven\n\nTo add a dependency on spring-testcontainer using Maven, use the following:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eme.paulbares\u003c/groupId\u003e\n    \u003cartifactId\u003espring-testcontainer\u003c/artifactId\u003e\n    \u003cversion\u003e1.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n# Important\nPer test class, only one field annotated with `@Container` is expected and this field must be static meaning only one docker \ncontainer will be started for all the tests within this class. \n\n# FAQ\n- How can I check my test is correctly setup?\nYou can verify in your test the connection url with the datasource:\n```java\n@Autowired\nDataSource dataSource;\n...\nString url = this.dataSource.getConnection().getMetaData().getURL();  // Value is jdbc:mysql://localhost:33349/test for a mysql db.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulbares%2Fspring-testcontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulbares%2Fspring-testcontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulbares%2Fspring-testcontainer/lists"}