import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class AssumptionsTest {
@Test
void testWithAssumeTrue() {
assumeTrue(5 > 1, "Assumption failed: 5 is not greater than 1");
// This assertion runs only if assumption is true
assertTrue(3 < 4, "3 should be less than 4");
}
@Test
void testWithAssumeFalse() {
assumeFalse(2 > 3, "Assumption failed: 2 is greater than 3");
// This assertion runs only if assumption is false
assertEquals(10, 5 + 5, "5 + 5 should equal 10");
}
}
The code imports assumeTrue and assumeFalse from JUnit 5 to conditionally run tests.
In testWithAssumeTrue, the assumption 5 > 1 is true, so the test continues and the assertion 3 < 4 passes.
In testWithAssumeFalse, the assumption 2 > 3 is false, so assumeFalse passes and the test runs the assertion 5 + 5 == 10.
If an assumption fails, the test is skipped, not failed. This helps when tests depend on certain conditions.