Testing is an essential skill for any Java developer. It helps you ensure the quality and reliability of your code, as well as find and fix bugs faster. On this page, you will find a collection of tutorials that will teach you how to test Java code using JUnit 5 and Mockito.
JUnit 5 is the latest version of the most popular testing framework for Java. Mockito is a powerful mocking library that allows you to create and use mock objects in your tests. You will learn how to write uit tests, integration tests, and test-driven development with JUnit 5 and Mockito. You will also learn how to test Spring Boot applications, which are widely used for building web services and microservices. All tutorials are designed for beginners, so you can start testing your Java code right away.
JUnit 5 Tutorials
- What is JUnit 5? (Includes Video tutorial)
- JUnit 5 – How to Structure Unit Test Method? (Includes Video tutorial)
- JUnit 5 – @Display annotation, (Includes Video tutorial)
- JUnit 5 – @Disabled annotation. How to Disable JUnit Test Method. (Includes Video tutorial)
- JUnit 5 – @TestPropertySource annotation,
- JUnit 5 – @TestMethodOrder and @Order annotations. How to Run JUnit Tests in Order?
- JUnit 5 – @BeforeAll, @AfterAll, @BeaforeEach, @AfterEach. A Guide to JUnit5 Lifecycle Methods,
- JUnit 5 – @RepeatedTest and @ParametrizedTest,
- An Overview of JUnit 5 Assertions with Examples,
- JUnit 5 – @EnableOnOs, @EnableOnJre, @DisabledForJreRange. A guide to conditional tests execution using JUnit5,
- JUnit 5 Lazy Assertion Message Tutorial, (Includes Video tutorial)
- Test for Exception in JUnit 5 and JUnit 4,
- JUnit 5 – @Suite. Test Suite Tutorial,
- JUnit 5 – @Tag annotation. Organizing and Running Tests in JUnit 5,
- Running a Single Unit Test with Maven,
- How to Skip Unit Tests in Maven,(Includes Video tutorial)
- Run JUnit 5 Test Methods from Command Line without Maven or Gradle
Mockito Tutorials
- An Introduction to the Mockito Framework,
- A Guide to Mocking Private and Static Methods Using PowerMock,
- How to use @MockBean Annotation,
- @MockBean Annotation Example,
- Getting Started with Mockito @Mock and @InjectMocks,
- Mockito Argument Matchers: Examples and Usage,
- Testing Spring Boot Applications with MockMvc,
- How to Mock Objects and Stub Methods with Mockito?
- Mockito Spy Explained: A Comprehensive Guide,
- Mockito – Call a Real Method.
Testing Spring Boot Applications
- JUnit Support in Spring Boot,
- @SpringBootTest Annotation Example,
- Difference Between @SpringBootTest and @WebMvcTest,
- Disable Spring Security Configuration for @WebMvcTest,
- Testing Method Security in Spring Boot,
- Get List of Objects with TestRestTemplate,
- TestRestTemplate HTTP Post Example,
- Integration Testing with Spring Boot, MySQL and Testcontainers,
- Running Unit Tests and Integration Tests Separately in Spring Boot Application.
Testing RESTful Web Services with REST Assured
- Testing RESTful Web Service API with REST Assured
- REST Assured: HTTP Post Request ( Includes video tutorial )
- REST Assured: Validate HTTP Status Code
- REST Assured: GET HTTP Header Value
- Rest Assured: HTTP Request with Query Parameters
- REST Assured: GET HTTP Response Body
- Validate Response Body Containing JSON
- Create a JUnit 5 Test Case with Rest Assured. ( Includes video tutorial )
- How to Run JUnit Tests in Specific Order