import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SampleUnitTest {
@Test
void testAddition() {
int result = 2 + 3;
assertEquals(5, result, "2 + 3 should equal 5");
}
@Test
void testStringContains() {
String text = "Hello CI Pipeline";
assertTrue(text.contains("CI"), "Text should contain 'CI'");
}
@Test
void testArrayNotEmpty() {
int[] numbers = {1, 2, 3};
assertNotEquals(0, numbers.length, "Array should not be empty");
}
}This JUnit 5 test class SampleUnitTest contains three simple unit tests.
Each test method is annotated with @Test so the CI pipeline test stage will detect and run them automatically.
Assertions check expected outcomes: assertEquals verifies addition, assertTrue checks string content, and assertNotEquals ensures the array is not empty.
When the CI pipeline runs mvn test, it will execute these tests and report results. If all assertions pass, the test stage will succeed.
This setup ensures the CI pipeline test stage runs unit tests and reports results as expected.