Mockito

Mockito Argument Matchers - any(), eq() — step-by-step Programming tutorial on Progressive Robot

Mockito Argument Matchers – any(), eq()

URL: https://www.progressiverobot.com/mockito-argument-matchers-any-eq/ Mockito allows us to create mock objects and stub the behavior for our test cases. We usually mock the behavior using when() and thenReturn() on the mock object. Mockito Argument Matchers – any() Sometimes we want to mock the behavior for any argument of the given type, in that case, we can use […]

Read more
Mockito ArgumentCaptor, @Captor Annotation — step-by-step Programming tutorial on Progressive Robot

Mockito ArgumentCaptor, @Captor Annotation

URL: https://www.progressiverobot.com/mockito-argumentcaptor-captor-annotation/ Mockito ArgumentCaptor is used to capture arguments for mocked methods. ArgumentCaptor is used with [Mockito verify()](/community/tutorials/mockito-verify) methods to get the arguments passed when any method is called. This way, we can provide additional [JUnit assertions](/community/tutorials/junit-assertions) for our tests. Mockito ArgumentCaptor We can create ArgumentCaptor instance for any class, then its capture() method is […]

Read more
Mockito @InjectMocks - Mocks Dependency Injection — step-by-step Programming tutorial on Progressive Robot

Mockito @InjectMocks – Mocks Dependency Injection

URL: https://www.progressiverobot.com/mockito-injectmocks-mocks-dependency-injection/ Mockito @InjectMocks annotations allow us to inject mocked dependencies in the annotated class mocked object. This is useful when we have external dependencies in the class we want to mock. We can specify the mock objects to be injected using [@Mock](/community/tutorials/mockito-mock-examples) or [@Spy](/community/tutorials/mockito-spy-partial-mock) annotations. Mockito @InjectMocks Mockito tries to inject mocked dependencies using […]

Read more
Mockito mock examples — step-by-step Programming tutorial on Progressive Robot

Mockito mock examples

URL: https://www.progressiverobot.com/mockito-mock-examples/ Mockito mocking framework provides different ways to mock a class. Let's look at different methods through which we can mock a class and stub its behaviors. Mockito mock method We can use [Mockito](/community/tutorials/mockito-tutorial) class mock() method to create a mock object of a given class or interface. This is the simplest way to […]

Read more
Mockito Mock Static Method - PowerMock — step-by-step Programming tutorial on Progressive Robot

Mockito Mock Static Method – PowerMock

URL: https://www.progressiverobot.com/mockito-mock-static-method-powermock/ Mockito allows us to create mock objects. Since static method belongs to the class, there is no way in Mockito to mock static methods. However, we can use PowerMock along with Mockito framework to mock static methods. Mockito Mock Static Method using PowerMock PowerMock provides different modules to extend [Mockito framework](/community/tutorials/mockito-tutorial) and run […]

Read more
Mockito Mock Void Method — step-by-step Programming tutorial on Progressive Robot

Mockito Mock Void Method

URL: https://www.progressiverobot.com/mockito-mock-void-method/ Most of the times Mockito when() method is good enough to mock an object's behavior. But when we have to mock a void method, we can't use when(). Mockito Mock Void Method Mockito provides following methods that can be used to mock void methods. doAnswer(): We can use this to perform some operations […]

Read more
Mockito Tutorial — step-by-step Programming tutorial on Progressive Robot

Mockito Tutorial

URL: https://www.progressiverobot.com/mockito-tutorial/ Mockito is a java based mocking framework, used in conjunction with other testing frameworks such as [JUnit](/community/tutorials/junit5-tutorial) and [TestNG](/community/tutorials/testng-tutorial). It internally uses [Java Reflection](/community/tutorials/java-reflection-example-tutorial) API and allows to create objects of a service. A mock object returns a dummy data and avoids external dependencies. It simplifies the development of tests by mocking external […]

Read more
Mockito Verify — step-by-step Programming tutorial on Progressive Robot

Mockito Verify

URL: https://www.progressiverobot.com/mockito-verify/ Mockito Verify methods are used to check that certain behavior happened. We can use Mockito verify methods at the end of the testing method code to make sure that specified methods are called. Mockito Verify Mockito verify() method can be used to test number of method invocations too. We can test exact number […]

Read more
CHAT