我有一个关于测试的问题。 有一个带有处理程序方法的 Controller :
@Controller
@RequestMapping("/something")
public class MyController{
@RequestMapping(value = "/getSomething" , method = POST, produces = {JSON}, consumes = {JSON})
@ResponseBody
public MyClass2 getSomething(@RequestBody MyClass myObj) {
.........
}
}
我应该在我的测试中做任何注解的验证吗? 喜欢:
@Test
public void verityMethodGetSomethihg(){
//check that there is the POST method
//check that the method produces a JSON
//check that the method consumes a JSON
}
附言 另外,我是否应该检查任何地方是否有方法处理程序/getSomething 的映射?
谢谢
最佳答案
你应该做什么取决于你。如果你认为这是一个有用的测试,那就去做吧。如果您认为它没有用,例如,因为您有一个广泛的功能测试套件来测试您的应用程序,那么就不要这样做。
现在怎么办? Spring MVC 带有一个测试框架,允许启动一个伪造的 Web 应用程序上下文,向您的应用程序发送请求并测试结果。 the documentation 中对其进行了广泛描述.
关于spring-mvc - spring mvc 测试 - 验证注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24862063/