JUnit Interview Guide
JUnit Interview Guide
1. What is JUnit?
JUnit is a unit testing framework for Java programming language. It helps developers write and run
repeatable tests.
- JUnit 4 and JUnit 5 (also called Jupiter) are the most commonly used versions.
2. JUnit 5 Architecture
4. Assertions
- assertEquals(expected, actual)
- assertTrue(condition)
- assertFalse(condition)
5. Parameterized Tests
Example:
@ParameterizedTest
assertTrue(isPalindrome(word));
Basic Example:
@Mock
@InjectMocks
@BeforeEach
void setup() {
MockitoAnnotations.openMocks(this);
@Test
void testServiceCall() {
when(service.getData()).thenReturn("Mocked");
assertEquals("Mocked", controller.fetchData());
7. JUnit 4 vs JUnit 5
|-----------------|----------------|------------------|
8. Best Practices
JUnit Interview Guide
9. Interview Questions