본문 바로가기

Spring boot

[spring boot] test시 (H2 DB의) 메모리모드 사용

test할 때 DB까지 왔다갔다하기 번거롭다면, 메모리를 사용하자. (DB를 꺼놔도 Test 실행가능)

 

1. H2 DB 메모리 모드사용

main>resources > application.yml 을 복사해

test > resources > application.yml에 붙이고 url만 변경하기(아래 참고)

//test > resources > application.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.level:
  org.hibernate.SQL: debug
  org.hibernate.type: trace

 

변경할 메모리 URL 주소찾기

H2접속 > Cheat Sheet

https://www.h2database.com/html/main.html

in-Memory 아래 주소 사용 

jdbc:h2:mem:test

jdbc:h2:mem:test

 

 

2. Spring boot의 메모리모드

application.yml에 따로 설정이 없다면 spring boot가 메모리 모드로 만들어줌.

//test > resources > applicaion.yml
 
logging.level:
  org.hibernate.SQL: debug
  org.hibernate.type: trace