Tôi có một trường hợp thử nghiệm rất đơn giản đó là sử dụng Mockito và Spring framework thử nghiệm. Khi tôi làmMockito ngoại lệ - khi() yêu cầu một cuộc tranh cãi đó có phải là một lời gọi phương thức trên một giả
when(pcUserService.read("1")).thenReturn(pcUser);
Tôi nhận ngoại lệ này.
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
at com.project.cleaner.controller.test.PcUserControllerTest.shouldGetPcUser(PcUserControllerTest.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
Tôi đã thử với các phương pháp khác nhau nhưng tiếp tục nhận được thông báo lỗi này. Tôi đang sử dụng Spring 3.1.0.RELEASE với Mockito. Hãy chia sẻ và hướng dẫn tôi đi đúng hướng.
Tôi cũng gặp vấn đề tương tự, nhưng tôi đang sử dụng: @Autowired @ReplaceWithMock (beanName = "logDao") riêng LogDao logDaoMock; –