MockMvcBuilder.standaloneMvcSet(new TestController()).build() .perform(get("/form")) .andExpect(status().isOk()) .andExpect(content().type("text/plain")) .andExpect(content().string("hello world")); 1. NullpointerException이 발생한다. TestController controller = new TestController(); MockHttpServletRequest req = new MockHttpRequest(); MockHttpServletResponse res = new MockHttpResponse(); ModelAndView mav = controller.form(req,res); assertThat(res.getStatus(),is(200)); 1. 두 매개변수는 @MVC에서 자주 사용하지 않는 매개변수이다. ==> @RequestMapping @ModelAttribute Model 2. 결과타입은 ModelAndView로 가정한다. ==> String (View 이름만 반환) void도 많다. 단위테스트 모든 객체의 Mock객체를 만들어서 컨트롤러에 주입테스트 통합테스트 테스트용 ApplicationContext만들어 비 주입 기능을 사용해야 한다. ==> TestContext라는 기능으로 지원하고 ApplicationContext 공유 기능을 제공한다. ApplicationContext를 한 번만 만들어서 TestContext에 캐시하여 사용한다. @RunWith(SpringJUnit4ClassRunner.class) @contextConfiguration("/testContext.xml") public class TestClassA{ } ==>@RunWith @ContextConfiguration @Autowired @Inject Spring-Test-MVC 와 TestContext 연동 @Autowired ApplicationContext context; --> MockMvc MockMvc mockMvc = MockMvcBuilders.applicationContextMvcSetup(context).configureWasRootDir("src/test/webapp",false).build(); Spring-Test-MVC는 ApplicationContext 타입의 객체로 MockMvc 객체를 마드는 메서드를 제공하지 않는다. WebApplicatioinContext 타입은 가능하다.