In JUnit, what happens when an assumption fails during test execution?
Think about what assumptions are used for in conditional test execution.
When an assumption fails, JUnit skips the test instead of failing it. This helps avoid false failures when preconditions are not met.
What is the test result when the following JUnit test runs?
import static org.junit.jupiter.api.Assumptions.*; import org.junit.jupiter.api.Test; public class SampleTest { @Test void testOnlyOnWindows() { assumeTrue(System.getProperty("os.name").startsWith("Windows")); // test code here } }
Check what assumeTrue does when the condition is false.
The assumeTrue method skips the test if the condition is false, so on non-Windows OS the test is skipped.
Which code snippet correctly uses assumptions to skip a test when a required environment variable is missing?
Remember assumptions skip tests when conditions are false.
assumeTrue skips the test if the condition is false. Option B correctly skips when API_KEY is missing.
Given the code below, why does the test fail instead of skipping when the assumption is false?
import static org.junit.jupiter.api.Assumptions.*; import org.junit.jupiter.api.Test; public class DebugTest { @Test void test() { if (!System.getProperty("user.name").equals("admin")) { assumeTrue(false, "Only admin can run this test"); } assertTrue(true); } }
Check the logic of the if condition and when assumeTrue is called.
The if condition is inverted or incorrect, so assumeTrue(false) is not called when expected, causing the test to fail instead of skip.
Which statement best describes how assumptions affect the execution of lifecycle methods (@BeforeEach, @AfterEach) in JUnit 5?
Consider what happens when setup assumptions fail before the test runs.
If an assumption fails in @BeforeEach, JUnit skips the test and does not run @AfterEach because the test was never executed.