Project-MO-A / MOA-Backend

MO:A is a web application that provides group study or team project services
1 stars 2 forks source link

test: 테스트 격리를 위한 테스트 코드 리팩토링 #58

Closed KAispread closed 1 year ago

KAispread commented 1 year ago

Issue: #51

DONE

test: Repository, Service 테스트 격리 test: fixture 객체를 통한 테스트용 엔티티 생성 refactor: 일부 코드 리팩토링

KAispread commented 1 year ago

우선 Controller 제외하고 나머지 테스트 코드는 리팩토링 했습니다. main 코드에 일부 변경점이 있으니 확인 부탁드려요

KAispread commented 1 year ago

아 그리고 Controller 테스트에서 계속 403에러가 나는데 이전에 추가한 권한 관련된 부분때문일까요? Controller 테스트 어떻게 하셨는지 궁금합니다.

Juhongseok commented 1 year ago

Controller 테스트 경우에는 403에러가 나는 이유가 MockMvc를 Autowired를 사용해 가져오니 @WebMvcTest 때문에 Security Filter도 같이 불려오는 것 같아요 그래서 MockMvc를 자동 주입을 받는 것이 아니라 직접 설정하는 방식을 사용하니 Security 설정을 가져오지 않더라고요

지금 당장 Controller test를 진행하는 것이 Controller만 단독적으로 테스트를 하는 것이지 굳이 Security까지 불러 올 필요가 없다고 생각도 했고요

mockMvc 적용 코드입니다

@BeforeEach
void setup(WebApplicationContext context, RestDocumentationContextProvider restDocumentation) {
    mvc = MockMvcBuilders
            .webAppContextSetup(context)
            .apply(documentationConfiguration(restDocumentation))
            .build();
}

Controller test 상단에 붙힌 어노테이션들 입니다

@AutoConfigureRestDocs
@ExtendWith(RestDocumentationExtension.class)
@WebMvcTest(AttendMemberController.class)
@Import(WebBeanConfig.class)
Juhongseok commented 1 year ago

코드 충돌나는 부분은 단순히 중복된거길래 하나 제거했어요

KAispread commented 1 year ago

리뷰 감사합니다😊 Controller 테스트까지 작성해서 Push 할게요