JUnit is a Java testing framework used for unit testing and ensuring code correctness.
Explanation:
- Provides annotations like
@Test
,@Before
,@After
to structure tests. - Supports assertions (
assertEquals
,assertTrue
) to validate expected outputs. - Integrated with Maven, Gradle, and CI/CD tools.
Example JUnit Test:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CalculatorTest {
@Test
public void testAddition() {
assertEquals(5, 2 + 3);
}
}
- This test checks if
2 + 3
correctly returns5
.
Leave a Reply