Testing Jakarta EE REST APIs with Mockito and JUnit 5
Here’s the revised version using @ExtendWith and @InjectMocks for CDI-style mocking: Testing Jakarta EE REST APIs with Mockito and JUnit 5Discover how to test Jakarta EE 10 APIs without a server using Mockito’s dependency injection and JUnit 5 extensions. 1. Maven Dependencies Add these testing frameworks to your pom.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
xml<code><dependencies> <em><!-- Jakarta EE 10 API --></em> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> <version>10.0.0</version> <scope>provided</scope> </dependency> <em><!-- Testing --></em> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.9.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-junit-jupiter</artifactId> <version>5.4.0</version> <scope>test</scope> </dependency> </dependencies> |
2. REST Resource with CDI … Read more