Final answer:
To mock an auto wired object in Mockito, use the Mock annotation along with InjectMocks and MockitoJUnitRunner in your test class.
Step-by-step explanation:
In order to mock an auto wired object using Mockito, you can use the Mock annotation along with InjectMocks and MockitoJUnitRunner in your test class.
Here is an example:
- Create a test class and annotate it with RunWith (MockitoJUnitRunner.class).
- Annotate the object you want to mock with Mock.
- Create an instance of the class that contains the auto wired object and annotate it with InjectMocks.
- Write your test cases and use Mockito's when and then Return methods to mock the behavior of the autowired object.
To mock an autowired object in Mockito, use Mock to create a mock instance and InjectMocks to inject it into the class under test. Initialize the mocks using either MockitoAnnotations.initMocks(this) for Mockito before 2.24, or open Mocks(this) for later versions, or use the ExtendWith (MockitoExtension.class) annotation with JUnit 5.