Learn how to write clear and solid unit tests with JUnit and Mockito. This page gives you a simple guide to what you will study in the course. You see the key skills you will build and how each step fits into real Java work.
What You Will Learn
You take 12 steps with JUnit and 18 steps with Mockito. Each step shows you a small idea. You use that idea in short and focused tests. By the end, you know how to test code with less setup and fewer mistakes.
Mockito Steps
Start With Mocks
- Set up a project with JUnit and Mockito. Run your first green test.
- See why mocks help you test code that calls other classes.
- Learn what a stub is. Write a test with a stub and see its limits.
- Write your first mock with Mockito. Mock a simple service.
Stubbing and Verification
- Stub methods with return values, matchers, and errors.
- Use simple BDD terms: Given, When, Then. Write tests with BDD style.
- Check how many times a method runs on a mock.
- Capture values passed into a mock using an argument captor.
Useful Mockito Tools
- Use Hamcrest matchers to improve test checks.
- Use annotations like @Mock, @InjectMocks, and @Captor.
- Learn how MockitoJUnit.rule() works.
- Apply Mockito in a small Spring example.
Advanced Mocking
- Spy on real objects and see when to use a spy.
- Learn why Mockito does not mock final or private methods.
- Use PowerMock to mock static methods.
- Call private methods with PowerMock.
- Mock a constructor when needed.
- Review what makes a good unit test.
JUnit Steps
Start With Basics
- See why unit tests matter in everyday Java work.
- Set up your first JUnit test.
- Write a simple assertEquals test.
- Refactor your first test to make it cleaner.
Core Test Skills
- Use assertTrue and assertFalse.
- Run setup and cleanup code with @Before and @After.
- Run class‑level setup with @BeforeClass and @AfterClass.
- Compare arrays in a test.
More JUnit Tools
- Test expected errors.
- Measure simple performance with JUnit tools.
- Write parameterized tests.
- Group tests into suites.