Challenge - 5 Problems
Assumptions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test execution result of this JUnit code snippet?
Consider the following JUnit 5 test method using assumeTrue. What will be the test execution result?
JUnit
import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.junit.jupiter.api.Test; public class SampleTest { @Test void testAssumption() { assumeTrue(2 + 2 == 4); System.out.println("Assumption passed"); } }
Attempts:
2 left
💡 Hint
assumeTrue continues test only if condition is true
✗ Incorrect
The assumeTrue condition is true, so the test continues and passes, printing the message.
❓ Predict Output
intermediate2:00remaining
What happens when assumeFalse condition is true in this test?
Look at this JUnit 5 test method using assumeFalse. What will be the test execution result?
JUnit
import static org.junit.jupiter.api.Assumptions.assumeFalse; import org.junit.jupiter.api.Test; public class SampleTest { @Test void testAssumptionFalse() { assumeFalse(5 > 3); System.out.println("Assumption false passed"); } }
Attempts:
2 left
💡 Hint
assumeFalse skips test if condition is true
✗ Incorrect
The assumeFalse condition is true, so the test is skipped and does not print the message.
❓ assertion
advanced2:00remaining
Which assertion correctly uses assumeTrue to skip test if environment variable is missing?
You want to skip a test if the environment variable 'ENV' is not set. Which assumeTrue statement achieves this?
Attempts:
2 left
💡 Hint
assumeTrue continues only if condition is true
✗ Incorrect
assumeTrue(System.getenv("ENV") != null) continues test only if ENV is set (not null).
🔧 Debug
advanced2:00remaining
Why does this test never run its assertions?
Examine this JUnit 5 test method. Why are the assertions never executed?
JUnit
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; public class SampleTest { @Test void testSkipped() { assumeTrue(false); assertEquals(5, 2 + 3); } }
Attempts:
2 left
💡 Hint
assumeTrue skips test if condition is false
✗ Incorrect
assumeTrue(false) skips the test immediately, so assertions are never reached.
🧠 Conceptual
expert2:00remaining
What is the main difference between assumeTrue and assertTrue in JUnit?
Choose the best explanation of how assumeTrue differs from assertTrue in JUnit testing.
Attempts:
2 left
💡 Hint
Think about test skipping versus test failure
✗ Incorrect
assumeTrue skips tests when conditions are not met; assertTrue causes test failure on false condition.