반응형

JUnit 3

[junit] Auditor must not be null! Returned by: class com.example.demo.db.LoginUserAuditorAware!

Junit 테스트 코드를 작성하는 도중 Auditor must not be null 에러가 발생하였습니다. 증상 Junit 테스트 할 로직 중 SecurityContext 정보를 조회할 필요가 있었습니다. 그래서 @BeforeEach 메서드에서 SecurityContext를 Mock으로 임의의 데이터를 넣고 @Test를 실행하는 경우였습니다. @BeforeEach void setUp() { // SecurityContext에서 가져올 유저 정보 UserVo userVo = new UserVo(); userVo.setUserId(1L); List roleNames = Arrays.asList("ROLE_ADMIN"); // userDetails Mock 설정 UserDetails userDetails = ..

TroubleShooting 2020.12.04

Spring Data JPA 기반 Querydsl 사용해보자. ( Entity 관계 매핑 X편, 테스트 코드 포함 )

이전글 Querydsl 사용해보자. ( 설정편 )에서 설정하는 방법을 알아보았습니다. Entity 관계 매핑되있는 경우는Querydsl 사용해보자. ( Entity 관계 매핑 편, 테스트 코드 포함 )참조해주세요. 이번 글에서는 Querydsl의 버전업으로 Entity 관계 매핑되어있지 않아도 사용가능해졌기 때문에 Querydsl 사용편에 대해서 알아봅시다. 모든 소스는 github에 올려두었습니다. Entity package com.example.querydsl.staff.entity; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import javax.pers..

Develop/spring-data 2020.11.08

JPA 테스트 코드로 알아보자!

JPA 설정 및 테스트 코드 작성은 이전글에 작성하였습니다. 이번글에서 다루는 소스코드는 github에 있습니다. JPA 저장 후 조회 @Test void entity저장후조회() { //given final Long id = 1L; final String storeName = "스토어1"; final String storeAddress = "주소1"; Store store = Store.builder() .id(id) .name(storeName) .address(storeAddress) .build(); storeRepository.save(store); //when Store resultStore = storeRepository.findByName(storeName); //then Assertion..

Develop/spring-data 2020.11.05
728x90
반응형