import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.Files;
import java.nio.file.Path;
public class SampleTest {
@Test
void testAddition() {
int sum = 2 + 3;
assertEquals(5, sum, "2 + 3 should equal 5");
}
@Test
void testSubtraction() {
int diff = 5 - 3;
assertEquals(2, diff, "5 - 3 should equal 2");
}
@Test
void testFailingCase() {
assertTrue(false, "This test is designed to fail");
}
@Test
void verifyReportExists() throws Exception {
// Assuming Maven default surefire report location
Path reportPath = Path.of("target", "surefire-reports", "TEST-SampleTest.xml");
assertTrue(Files.exists(reportPath), "Test report file should exist after tests run");
}
}This JUnit 5 test class SampleTest contains three test methods: two that pass and one that fails to demonstrate test result variety.
The verifyReportExists test checks if the test report file is generated in the default Maven Surefire reports folder. This confirms that test results are published after execution.
Assertions use JUnit's assertEquals and assertTrue for clarity. The report path uses Path.of with relative folders to avoid hardcoding absolute paths.
Run these tests via Maven or Gradle to generate the reports automatically. The failing test shows how failures appear in reports.