Firstly, you need the pom.xml entry to bring in the Mockito library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
... <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.9.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-runner</artifactId> <version>1.9.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>3.10.0</version> <scope>test</scope> </dependency> ... |
@InjectMocks
Firstly, annotate the Test class with @RunWith(MockitoJUnitRunner.class) as shown below. The @InjectMocks annotation creates an instance of the class and injects the mocks that are created with the @Mock (or @Spy) annotations into this instance.
…
Read more ›