dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-devtools'
compile('com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.7')
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/Dev/projects/book/db;MVCC=TRUE
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
package com.ym.book.shop.service;
import com.ym.book.shop.domain.entity.Member;
import com.ym.book.shop.repository.MemberRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
public class MemberServiceTest {
@Autowired
MemberService memberService;
@Autowired
MemberRepository memberRepository;
@Test
public void 회원가입()throws Exception{
//given
Member member = new Member();
member.setName("Kim");
//when
Long saveId = memberService.join(member);
//then
assertEquals(member, memberRepository.findOne(saveId));
}
@Test
public void 중복_회원_예외()throws Exception{
//given
//when
//then
}
}
결과 :
2019-10-06 14:52:56.074 INFO 2244 --- [ Test worker] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2019-10-06 14:52:56.173 DEBUG 2244 --- [ Test worker] org.hibernate.SQL :
select
member0_.member_id as member_i1_4_,
member0_.city as city2_4_,
member0_.street as street3_4_,
member0_.zipcode as zipcode4_4_,
member0_.name as name5_4_
from
member member0_
where
member0_.name=?
Hibernate:
select
member0_.member_id as member_i1_4_,
member0_.city as city2_4_,
member0_.street as street3_4_,
member0_.zipcode as zipcode4_4_,
member0_.name as name5_4_
from
member member0_
where
member0_.name=?
2019-10-06 14:52:56.204 DEBUG 2244 --- [ Test worker] org.hibernate.SQL :
insert
into
member
(member_id, city, street, zipcode, name)
values
(null, ?, ?, ?, ?)
Hibernate:
insert
into
member
(member_id, city, street, zipcode, name)
values
(null, ?, ?, ?, ?)
2019-10-06 14:52:56.216 INFO 2244 --- [ Test worker] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@4d40c3e testClass = MemberServiceTest, testInstance = com.ym.book.shop.service.MemberServiceTest@b322034, testMethod = 회원가입@MemberServiceTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@1ee9b049 testClass = MemberServiceTest, locations = '{}', classes = '{class com.ym.book.shop.ShopApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@275315df, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@47bf348f, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7db5eaa6, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@2cda0ac3], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true]]
2019-10-06 14:52:56.223 INFO 2244 --- [ Thread-6] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2019-10-06 14:52:56.223 INFO 2244 --- [ Thread-6] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-10-06 14:52:56.226 INFO 2244 --- [ Thread-6] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-10-06 14:52:56.231 INFO 2244 --- [ Thread-6] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
BUILD SUCCESSFUL in 5s
5 actionable tasks: 3 executed, 2 up-to-date
2:52:56 PM: Tasks execution finished ':cleanTest :test --tests "com.ym.book.shop.service.MemberServiceTest.회원가입"'.
이렇게 결과가 나옵니다.
select, insert가 2번씩 실행이 되는데요
혹시 제가 설정이 잘못된 게 있을까요?