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+.

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.