This repository is focused on learning and practicing Mockito and JUnit, two of the most popular Java frameworks for unit testing and mocking. It includes many examples covering both basic concepts and more advanced testing scenarios.
- Need for Unit Testing
- Setting up a JUnit Test
- Understanding
assertEquals,assertTrue, andassertFalse - Using
@Before,@After,@BeforeClass, and@AfterClass - Array Comparison in Tests
- Testing Exceptions and Performance
- Parameterized Tests
- Organizing Tests into Suites
- Setting up JUnit and Mockito
- Mocks vs. Stubs
- Basic Mocking with Mockito
- Variations in Stubbing (return values, argument matchers, exceptions)
- Introduction to BDD Syntax
- Verifying Mock Interactions and Call Counts
- Capturing Arguments with Mocks
- Using Hamcrest Matchers
- Mockito Annotations (
@Mock,@InjectMocks,@Captor) - JUnit Rules with Mockito
- Real-World Example with Spring
- Using Spies with Mockito
- Limitations: Final and Private Methods
- PowerMock with Mockito for Static and Private Methods, Constructors
- Creating Effective Unit Tests
Each topic is represented by one or more tests, organized to make exploring each concept easy.