【发布时间】:2013-10-16 17:32:04
【问题描述】:
我有这门课要测试。此测试使用 mockMvc 对象。我认为这个对象发送 http 请求,这些请求处理控制器,其配置来自 pathToFile.xml
@ContextConfiguration(locations = { "classpath:/pathToFile.xml" })
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class CandidateControllerTest {
@Autowired
WebApplicationContext wac;
MockMvc mockMvc;
@Before
public void before() {
mockMvc = MockMvcBuilders.webApplicationContextSetup(wac).build();
}
...
}
我认为有时我想将控制器与其他配置一起使用。
什么意思?
CandidateControllerTest 测试CandidateController 类的方法
@Controller
CandidateController{
@Autowire
CandidateService candidateService;
@RequestMapping("/path")
public string handleSomething(Model model){
...
candidateService.doSomething();
...
return "viewName"
}
}
我想模拟 candidateService 发送的 http 请求到控制器,模拟 candidateService
真的吗?
【问题讨论】:
标签: java spring testing spring-mvc mocking