티스토리 뷰
728x90
0. JUint 4 기반의 테스트 코드이다.
1. MockMvc는 Web MVC Controller를 테스트 위해 만들어진 Unit Test용 클래스이다.
1-1 MockServletContext를 로딩하여 전체 application context 만들지 않고도 테스트 할 수 있게 해준다.
1-2 아래 코드에서 중요한 부분은 testMockMvc 메소드이다.
1-3 특정한 컨트롤러를 테스트할 수 있도록 도와주는 MockMvcBuilders를 제공한다.
1-4 perform 메소드를 통해 해당 컨트롤러의 메소드를 실행할 수 있고
1-5. MockMvcRequestBuilders, MockMvcResultMatchers의 get, status, view 메소드를 사용하여 상태를 확인한다.
1-6. get은 controller에 호출할 url을 지정하고, status는 해당 uri를 실행한 결과를 체크하는 함수이다.
package pe.pilseong.recipe.controller;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import pe.pilseong.recipe.service.RecipeService;
import org.junit.Before;
public class IndexControllerTest {
IndexController indexController;
@Mock
RecipeService recipeService;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
indexController = new IndexController(recipeService);
}
@Test
public void testMockMvC() throws Exception {
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(indexController).build();
mockMvc.perform(MockMvcRequestBuilders.get("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.view().name("main"));
}
@Test
public void test() {
}
}
728x90
'Spring > Spring Test' 카테고리의 다른 글
Spring Test : Maven Integration Test 설정하기 (0) | 2020.08.01 |
---|---|
Spring Test : Repository Integration Test with @RunWith, @DataJpaTest (0) | 2020.07.31 |
Spring Test : Argument 캡처하기 (0) | 2020.07.31 |
Spring Test : Controller 레이어 클래스 테스트 (0) | 2020.07.31 |
Spring Test : Service 레이어 클래스 테스트 (0) | 2020.07.31 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
TAG
- Many-To-Many
- form
- Angular
- 로그인
- Security
- Spring Security
- 스프링
- 스프링부트
- mapping
- login
- RestTemplate
- one-to-one
- crud
- one-to-many
- spring boot
- 상속
- Validation
- WebMvc
- hibernate
- 외부파일
- 설정
- MYSQL
- 하이버네이트
- 매핑
- Spring
- XML
- 자바
- jsp
- Rest
- 설정하기
250x250