Changes from Version 1 of test/summary

차이점 주위로
다음 차이점은 무시하기:
작성자:
anonymous (IP: 221.150.127.103)
날짜/시간:
2013-12-24 PM 3:44:58 (12 년 전)
설명:

--

Legend:

변경되지 않음
추가됨
제거됨
변경됨
  • test/summary

    v0 v1  
     1 
     2{{{ 
     3MockMvcBuilder.standaloneMvcSet(new TestController()).build() 
     4                .perform(get("/form")) 
     5                .andExpect(status().isOk()) 
     6                .andExpect(content().type("text/plain")) 
     7                .andExpect(content().string("hello world")); 
     8 
     9                1. NullpointerException이 발생한다. 
     10 
     11TestController controller = new TestController(); 
     12MockHttpServletRequest req = new MockHttpRequest(); 
     13MockHttpServletResponse res = new MockHttpResponse(); 
     14ModelAndView mav = controller.form(req,res); 
     15assertThat(res.getStatus(),is(200)); 
     16 
     17                1. 두 매개변수는 @MVC에서 자주 사용하지 않는 매개변수이다. 
     18                        ==>     @RequestMapping 
     19                                @ModelAttribute 
     20                                Model 
     21 
     22                2. 결과타입은 ModelAndView로 가정한다. 
     23                        ==>     String (View 이름만 반환) 
     24                                void도 많다. 
     25 
     26 
     27단위테스트 
     28        모든 객체의 Mock객체를 만들어서 컨트롤러에 주입테스트  
     29 
     30통합테스트 
     31        테스트용 ApplicationContext만들어 비 주입 기능을 사용해야 한다. 
     32        ==> TestContext라는 기능으로 지원하고 
     33            ApplicationContext 공유 기능을 제공한다. 
     34 
     35            ApplicationContext를 한 번만 만들어서 TestContext에 캐시하여 사용한다. 
     36 
     37                @RunWith(SpringJUnit4ClassRunner.class) 
     38                @contextConfiguration("/testContext.xml") 
     39                public class TestClassA{ 
     40 
     41                } 
     42 
     43                ==>@RunWith 
     44                   @ContextConfiguration 
     45                        @Autowired 
     46                        @Inject 
     47 
     48Spring-Test-MVC 와 TestContext 연동 
     49 
     50         
     51@Autowired ApplicationContext context; --> MockMvc 
     52 
     53MockMvc mockMvc = MockMvcBuilders.applicationContextMvcSetup(context).configureWasRootDir("src/test/webapp",false).build(); 
     54 
     55Spring-Test-MVC는 ApplicationContext 타입의 객체로 MockMvc 객체를 마드는 메서드를 제공하지 않는다. 
     56WebApplicatioinContext 타입은 가능하다. 
     57 
     58 
     59 
     60 
     61}}}