• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

WithMockUser 어노테이션 추가시 인식이안됩니다.

19.08.19 23:31 작성 조회수 780

0

WithMockUser 어노테이션 추가시  인식이안됩니다.

scope도 test로 지정했는데 왜그런지모르겟네요

cannot resolve Symbol이라는 메시지 뜨면서 

인식이 안됩니다.

소스첨부드리며 확인 부탁드립니다.

package me.izac.springbootsecurity;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

@RunWith(SpringRunner.class)
@WebMvcTest(HomeController.class)
public class HomeControllerTest {

@Autowired
MockMvc mockMvc;

@Test
@WithMockUser
public void hello() throws Exception {
mockMvc.perform(get("/hello"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("hello"));
}

@Test
public void hello_without_user() throws Exception {
mockMvc.perform(get("/hello"))
.andDo(print())
.andExpect(status().isUnauthorized());
}

@Test
@WithMockUser
public void my() throws Exception {
mockMvc.perform(get("/my"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("my"));
}

}


    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring-security.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

답변 2

·

답변을 작성해보세요.

0

이원준님의 프로필

이원준

질문자

2019.08.21

몇일 후에 다시해보니깐 되네요 우선 감사드립니다.

0

소스 코드 상에 문제는 없어 보이는데 그럼 혹시 이 import문은 직접 작성하신거에요? 인텔리J에서 자동완성으로 넣으신게 아니라?

import org.springframework.security.test.context.support.WithMockUser;

전체 코드를 깃헙에 올려주시면 좀 더 살펴보겠습니다.