Top "Mockito" questions

Mockito is a mocking framework for Java.

mockito callbacks and getting argument values

I'm not having any luck getting Mockito to capture function argument values! I am mocking a search engine index and …

java unit-testing mocking mockito
Simulate first call fails, second call succeeds

I want to use Mockito to test the (simplified) code below. I don't know how to tell Mockito to fail …

java mockito
Matchers.any() for null value in Mockito

Suppose I am having this object objectDemo which calls to the method objectDemoMethod with 2 parameters String and null. Now I …

java mockito
Mockito.any() for <T>

I want to mock a method with signature as: public <T> T documentToPojo(Document mongoDoc, Class<T&…

java unit-testing mockito mongodb-java springmockito
How to test DAO methods using Mockito?

I've started to discovered Mockito library and there is a question for which I didn't find the proper answer. If …

java unit-testing junit mockito dao
Difference between @Mock, @MockBean and Mockito.mock()

When creating tests and mocking dependencies, what is the difference between these three approaches? @MockBean: @MockBean MyService myservice; @Mock: @Mock …

java spring spring-boot junit mockito
Using PowerMockito.whenNew() is not getting mocked and original method is called

I have a code somewhat like this below: Class A { public boolean myMethod(someargs) { MyQueryClass query = new MyQueryClass(); Long id = …

java junit mockito powermock
How to use Mockito with JUnit5

How can I use injection with Mockito and JUnit 5? In JUnit4 I can just use the @RunWith(MockitoJUnitRunner.class) Annotation. …

java unit-testing mockito junit5
Why Can't I access src/test/resources in Junit test run with Maven?

I am having a problems running the following code: configService.setMainConfig("src/test/resources/MainConfig.xml"); From within a Junit @…

java junit4 mockito
Counting method invocations in Unit tests

What is the best way to count method invocations in a Unit Test. Do any of the testing frameworks allow …

unit-testing junit4 mockito jmockit