본문 바로가기

서버

Springboot3 - 테스트환경 메모리 모드로 설정

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