inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[워밍업 클럽 4기 백엔드] 3주차 발자국

cnline
1

image

학습 내용

  1. persistence layer 테스트

persistence layer

 

Repository test

통합 테스트이지만 해당 레이어만 띄워서 하기 때문에 단위 테스트 느낌이 난다

 

스프링 통합테스트를 위한 어노테이션

@springBootTest, @DataJpaTest차이

dataJpaTest : jpa 관련 빈 주입해서 서버를 띄워 빠르다

assertThat(product).hasSize(2)   - 사이즈 확인 
		.extrating("productNumber", "name" , "sellingStatus")   - 검증하고 싶은 셀만 확인 가능 
		.containsExactlyInAnyOrder(       -- 순서 상관없이 해당 것이 포함하는지 확인
			tuple("001", "아메리카노", selling),
			tuple("002", "카페라떼", HOLD)
	        )

 

  1. business layer 테스트

service 테스트

asserThat(orderResponse.getId).isNotNull();  -- null 이 아니다 

@springBootTest, @DataJpaTest차이

DataJpaTest 는 트랜잭션 어노테이션 있어 사용하면 자동으로 롤백이 된다

 

  1. presentation layer 테스트

     

presentation layer

 

@transactional(readOnly = true)

CRUD에서 CUD 동작 X, only read 만 가능

jpa : cud 스냅샷 저장, 변경 감지 x (성능 향상)

서비스 테스트를 할때 전체 클래스에 @transactional(readOnly = true) 를 걸고 각 command 작업을 하는 메서드에는 @transactional 따로 걸자

 

 

느낀점

 

백엔드

답변 0