테스트 코드 작성시 Mock HttpServletRequest 를 생성하는 방법.
srping-test
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("x-real-ip","127.0.0.1");
Mockito
HttpServletRequest mockedRequest = Mockito.mock(HttpServletRequest.class);
JMock
Mockery context = new Mockery();
HttpServletRequest mockedRequest = context.mock(HttpServletRequest.class);
참조 :
https://stackoverflow.com/questions/18889688/building-simple-http-header-for-junit-test
https://stackoverflow.com/questions/12945907/how-to-mock-the-httpservletrequest
http://jmock.org/getting-started.html
반응형