JUnit Basics

Running JUnit Tests with Maven

Learn to run JUnit tests using Maven Surefire Plugin. We will learn to run a single test, run only selected tests or run all the tests in the project.

Spring Boot Mockito JUnit Example: Unit Test a Service

Unit test a Spring Boot service with JUnit and Mockito. Mock the repository with @Mock, build the service with @InjectMocks, stub with when().thenReturn() and check calls with verify(). Also covers @MockitoBean in @SpringBootTest, thenThrow, ArgumentCaptor, BDDMockito, strict stubs and the Mockito Java agent on Java 21+.

Unit Testing Best Practices

It is overwhelmingly easy to write bad unit tests that add very little value to a project while astronomically inflating the cost of code changes. This post will go through the JUnit best practices we must consider while writing the test cases. In programming, “Unit testing is a method by …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.