https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.1.0

페이지 하단 코드 복사 후 pom.xml에 붙여넣기

 

src/test/java 경로에 JUnit Test Case 생성 후 작성

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({"file:src/main/webapp/WEB-INF/spring/root-context.xml",
	"file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml"})
public class MockMvcTest {

	private static final Logger log = 
			LoggerFactory.getLogger(MockMvcTest.class);
	
	@Autowired
	private WebApplicationContext ctx;
	
	private MockMvc mockMvc;
	
	@Before
	public void setup() {
		this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx).build();
	}
	
	@Test
	public void test() throws Exception {
		String resultPage = mockMvc	
                                .perform(MockMvcRequestBuilders.get("/sample/ex04")
                                .param("name", "홍길동")
                                .param("age", "18")
                                .param("page", "3"))
                                .andReturn().getModelAndView().getViewName();
		log.info("resultpage : " + resultPage);
	}

}

 

빈공간 우클릭하여 JUnit Test 실행

 

우측 JUnit탭에 초록색으로 표시되고 하단 콘솔창에 출력이 잘 된다면 테스트 성공!