Misplaced argument matcher detected here. You cannot use argument matchers outside of verification or stubbing in Mockito

前端 未结 3 1833
感动是毒
感动是毒 2021-01-01 09:27

Out of the following two test cases in BundleProcessorTest.java, i am getting below exception, although, my first test case passes successfully.

相关标签:
3条回答
  • 2021-01-01 10:03

    Simple, Should use @Spy annotation with @InjectMocks annotation.

    0 讨论(0)
  • 2021-01-01 10:12

    You are using mockito anyString() while calling the test method, it should be used only for verifying a mock object to ensure a certain method is called with any string parameter inside the test, but not to invoke the test itself. For your test use empty string "" instead to anyString().

    0 讨论(0)
  • 2021-01-01 10:29

    Ideally anyString() should not be used outside the mock or verify block.I was facing the same issue.Changing the anyString() to some string ("xyz") value works fine.

    Note : Make a note that you might use anyString() to some other methods that leads in failure of some other method. It wasted my one hour to figure it out. My actual test method was getting passes individually but when i was trying to run that in a hole it was getting failed because of the reason that some other test case was using anyString() outside to mock or verify block.

    0 讨论(0)
提交回复
热议问题