JUnit

This tutorial will guide you through the process of running Unit Tests and Integration Tests separately in a Maven-based Spring Boot application. We will use the JUnit Tag feature to group our test cases and separate Unit Tests from Integration Tests. To learn more, check out the Test Java code tutorials page. Create your tests…

Read More Running Unit Tests and Integration Tests Separately in Spring Boot

Welcome, and thank you for choosing this tutorial! If you’re an absolute beginner looking to learn about integration testing for Spring Boot applications with a MySQL database server, then you’re in the right place. As you proceed through this tutorial, remember that everyone was once a beginner, and the only silly question is the one…

Read More Integration Testing with Spring Boot, MySQL and Testcontainers

Mocking a static or private method is often necessary when writing unit tests. However, before Mockito 3.4.0, it was impossible to explicitly mock static methods. Thus, PowerMock offers solutions to the defined use case. In this article, we will look at the introduction of PowerMock and explore examples of mocking private, static, and final methods.…

Read More A Guide to Mocking Private and Static Methods Using PowerMock

This tutorial will guide you on how to incorporate JUnit support into your Spring Boot application based on Maven. Spring Boot Starter Test Dependency To add JUnit and Mockito support to your Maven-based Spring Boot application, include the following dependencies in the <dependencies> section of your pom.xml file: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> By adding…

Read More JUnit Support in Spring Boot

In this tutorial, you will learn how to write a JUnit test that validates whether the method under test throws the correct exception. The tutorial includes examples for both JUnit 5 and JUnit 4. For video lessons, check out my video course: Testing Java with JUnit and Mockito. Let’s begin with JUnit 5 version first.…

Read More Test for Exception in JUnit 5 and JUnit 4