Test Overview
This test checks if Mockito is correctly set up in a JUnit 5 project by verifying that a mock object is created and behaves as expected.
This test checks if Mockito is correctly set up in a JUnit 5 project by verifying that a mock object is created and behaves as expected.
import static org.mockito.Mockito.*; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.junit.jupiter.api.extension.ExtendWith; import static org.junit.jupiter.api.Assertions.*; import java.util.List; @ExtendWith(MockitoExtension.class) public class MockitoSetupTest { @Mock private List<String> mockedList; @Test public void testMockCreation() { // Arrange when(mockedList.size()).thenReturn(3); // Act int size = mockedList.size(); // Assert assertEquals(3, size, "Mocked list size should be 3"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and JUnit initializes the test class with MockitoExtension | JUnit test runner is ready; MockitoExtension prepares mocks | - | PASS |
| 2 | Mockito creates a mock instance of List<String> and injects it into mockedList | mockedList is a Mockito mock object | - | PASS |
| 3 | Test sets up behavior: when mockedList.size() is called, return 3 | mockedList configured to return 3 for size() | - | PASS |
| 4 | Test calls mockedList.size() | mockedList.size() returns 3 as configured | assertEquals(3, size) | PASS |
| 5 | Test finishes successfully with assertion passing | Test passed, mock works as expected | assertEquals passed | PASS |