선행 다운로드
- Docker Download
[Docker (1)] window10 Docker 설치하기(윈도우 10 도커 설치)
[Docker (1)] window10 Docker 설치하기(윈도우 10 도커 설치) 안녕하세요. 갓대희 입니다. 이번 포스팅은 [ Window10 도커 설치 ] 입니다. : ) 도커 설치하기 ▶ 1. 도커란? 도커 설치와 관련된 포스팅 이기.
goddaehee.tistory.com

postgreSql 의존성 추가(없으면, class not found 에러 발생)
TestContainers 설치
- Testcontainers JUnit 5 지원 모듈 설치
Jupiter / JUnit 5 - Testcontainers
Jupiter / JUnit 5 While Testcontainers is tightly coupled with the JUnit 4.x rule API, this module provides an API that is based on the JUnit Jupiter extension model. The extension supports two modes: containers that are restarted for every test method
www.testcontainers.org
- @Testcontainers = JUnit 5 확장팩으로 테스트 클래스에 @Container를 사용한 필드를 찾아서 컨테이너 라이프사이클 관련 메서드를 실행해준다.
- @Container = 인스턴스 필드에 사용하면 모든 테스트 마다 컨테이너를 재시작하고, 스태틱 필드에 사용하면 클래스 내부 모든 테스트에서 동일한 컨테이너를 재사용한다.
직접 컨테이너를 띄우고, 내리고 할 수 있다.
PostgreSQLContainer를 이제 만들수가 있다. 
이렇게 어노테이션을 활용해서 생성해도 된다. 
단 컨테이너가 인스턴스를 공유하기 떄문에 테스트를 실행후 데이터를 비워주어야 한다.
- 여러 모듈을 제공하는데, 각 모듈은 별도로 설치해야 한다.
- Postgresql 모듈 설치
- Test Containers가 Jdbc Url 을 모르기 때문에 이를 메핑 해 주어야 된다.(tc를 붙여주어야 한다)
- TestContainer 가 띄운 url을 Driver로 ContainerDatabaseDriver를 사용해야 한다.

- https://www.testcontainers.org/modules/databases/
-
Database containers - Testcontainers
Database containers Overview You might want to use Testcontainers' database support: Instead of H2 database for DAO unit tests that depend on database features that H2 doesn't emulate. Testcontainers is not as performant as H2, but does give you the be
www.testcontainers.org
- https://www.testcontainers.org/modules/databases/postgres/
-
Postgres Module - Testcontainers
www.testcontainers.org

testContainer를 Postgresql로 띄어야한다.
'더 자바, 애플리케이션을 테스트하는 다양한 방법' 카테고리의 다른 글
| Ch03. 도커와 테스트 - 컨테이너 정보를 스프링 테스트에서 참조하기 (0) | 2022.01.08 |
|---|---|
| Ch03. 도커와 테스트 - Testcontainers 기능 살펴보기 (0) | 2022.01.07 |
| Ch03. 도커와 테스트 - Testcontainers 소개 (0) | 2022.01.07 |
| Ch02. Mockito - BDD 스타일 Mockito API (0) | 2022.01.05 |
| Ch02. Mockito - Mock 객체 확인 (0) | 2022.01.05 |
