【发布时间】:2014-08-12 19:21:31
【问题描述】:
我正在尝试模拟 restTemplate.postForEntity 方法,
实际的方法调用是:
URI myUri = new URI(myString);
HttpEntity<String> myEntity ...
String myResponse = restTemplate.postForEntity(myUri, myEntity, String.class);
我的测试课是:
Mockito.when(restTemplate.postForEntity(any(URI.class), any(HttpEntity.class), eq(String.class))).thenReturn(response);
这不起作用;我尝试了其他几种排列也没有成功。任何建议表示赞赏,谢谢。
这不起作用我的意思是调用实际方法而不是模拟方法(因此不返回所需的结果等)
【问题讨论】:
-
这不起作用信息量不是很大。
-
只是一个不受欢迎的评论:模拟这种类通常是一种不好的做法。使用 Mock 的 TDD 的良好实践之一是不模拟您不拥有的类。
标签: java unit-testing testing mocking mockito