我有这门课要测试。此测试使用 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
用 mocked 模拟发送到控制器的 http 请求candidateService
真的吗?