@H_301_1@如何编写mockito junit的方法如下:
@Autowired RestTemplate restTemplate; ResponseEntity<?> execute(final String url,HttpMethod httpMethod,HttpEntity<?> entityRequest,String.class,Map<String,String> urlVariables){ restTemplate.exchange(url,httpMethod,entityRequest,responseType,urlVariables); }
请帮我写如何写
解决方法
@RunWith(MockitoJUnitRunner.class) public class ToTestTest { @InjectMocks private YourClass toTest; @Mock private RestTemplate template; @Test public void test() { toTest.execute(Mockito.anyString(),Mockito.any(),Mockito.any()); Mockito.verify(template,Mockito.times(1)) .exchange(Mockito.anyString(),Mockito.<HttpMethod> any(),Mockito.<HttpEntity<?>> any(),Mockito.<Class<?>> any(),Mockito.<String,String> anyMap()); } }