강의

멘토링

로드맵

인프런 커뮤니티 질문&답변

유승현님의 프로필 이미지
유승현

작성한 질문수

스프링과 JPA 기반 웹 애플리케이션 개발

회원 가입 리팩토링 및 테스트

mockMvs with 메서드 참조 관련

작성

·

771

0

package com.example.studybin.account;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;


import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@DisplayName("회원 가입 처리 - 입력값 오류")
@Test
void signUpSubmit_with_wrong_input() throws Exception {
mockMvc.perform(post("/sign-up")
.param("nickname", "soob")
.param("email", "email...")
.param("password", "12345"))
.with(csrf())
.andExpect(status().isOk())
.andExpect(view().name("account/sign-up"));
}

여기 post에서 with method를 찾을 수 없다고
Cannot resolve method 'with' in 'ResultActions'

이렇게 뜨는데 어떻게 해결해야 할까요

해당 패키지는 import하고 있는데 

왜 MockHttpServletRequestBuilder내에 있는 with를 참조 못할까요

패키지 버전 문제 때문에 그런것 같은데 정확히 어떻게 바꿔줘야 할질 모르겠습니다.

퀴즈

71%나 틀려요. 한번 도전해보세요!

회원 가입 시 이메일 인증 절차를 사용하는 가장 중요한 이유가 무엇일까요?

계정 도메인 모델의 복잡성 증가를 위해서

실제 사용자인지 확인하고 스팸 가입을 방지하기 위해

패스워드 인코딩 과정을 간소화하기 위해

프론트엔드 라이브러리 설정을 쉽게 하기 위해

답변 2

1

유승현님의 프로필 이미지
유승현
질문자

해당 패키지 내에 with있는것도 확인했는데 

리빌드를 하면 아래 에러가뜹니다.

java: cannot find symbol
  symbol:   method with(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessor)
  location: interface org.springframework.test.web.servlet.ResultActions

0

유승현님의 프로필 이미지
유승현
질문자

해결했습니다.
코드에 실수가 있었네요
실수 덕분에 패키지도 까보고 좋은경험했습니다

유승현님의 프로필 이미지
유승현

작성한 질문수

질문하기