728x90
Spring Boot 프로젝트 생성시
com.h2database:h2 를 가져오는데
해당 패키지로 db를 메모리 모드로 변환 시킬 수 있다.
먼저 테스트 환경에서 사용할 환경변수를 분리하자
1. 테스트 케이스시에 사용할 환경 분리
프로젝트 디렉토리는 다음과 같다.
src
-> main
-> test
test 디렉토리 하위에
resources를 생성해 yml을 다음과 같이 넣어주자
spring:
datasource:
url: jdbc:h2:mem:test;
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
show_sql: true
format_sql: true
logging:
org.hibernate.SQL: debug
test환경에서
설정이 없다면 기본적으로 memory 모드로 돌려주기 때문에
다음과 같이 셋팅을 생략하여도 됨.
spring:
# datasource:
# url: jdbc:h2:mem:test;
# username: sa
# password:
# driver-class-name: org.h2.Driver
# jpa:
# hibernate:
# ddl-auto: create
# properties:
# hibernate:
# show_sql: true
# format_sql: true
logging:
org.hibernate.SQL: debug
'서버' 카테고리의 다른 글
vscode 에서 java 버전 변경(java extension 설치 후 기본 버전(jdk21)으로 셋팅되는 경우) (0) | 2025.01.02 |
---|---|
Springboot3 - Exception 생성하기 (0) | 2024.12.30 |
Springboot3 - SpringBootTest에서 insert문 안 나가는 이유(@Transactional, @Rollback(false) (0) | 2024.12.30 |
Springboot - vscode에서 hot swapping 셋팅 (0) | 2024.12.26 |
github action - npm command not found 뜨는 현상 (0) | 2024.12.26 |