Recall & Review
beginner
What does the JUnit method
assumeTrue(condition) do in a test?It checks if the condition is true. If it is false, the test is skipped (ignored), not failed.
Click to reveal answer
beginner
How does
assumeFalse(condition) behave in a JUnit test?It checks if the condition is false. If the condition is true, the test is skipped (ignored).
Click to reveal answer
intermediate
Why use
assumeTrue or assumeFalse instead of assertTrue or assertFalse?Assumptions skip tests when conditions are not met, useful for environment checks. Assertions fail tests when conditions are not met.
Click to reveal answer
beginner
What happens to a test result if an assumption fails in JUnit?
The test is marked as skipped or ignored, not as failed or passed.
Click to reveal answer
beginner
Give a simple example of using
assumeTrue in a JUnit test.Example:<br>
assumeTrue(System.getProperty("os.name").startsWith("Windows"));
// test code that runs only on WindowsClick to reveal answer
What does
assumeTrue(false) do in a JUnit test?✗ Incorrect
If the condition is false, assumeTrue causes the test to be skipped, not failed.
Which method skips a test if the condition is true?
✗ Incorrect
assumeFalse skips the test if the condition is true.
When should you use assumptions in tests?
✗ Incorrect
Assumptions check if conditions are right to run the test; if not, the test is skipped.
What is the difference between
assumeTrue and assertTrue?✗ Incorrect
assumeTrue skips test when condition is false; assertTrue fails the test.
If an assumption fails, what is the test status?
✗ Incorrect
Failing an assumption causes the test to be skipped, not failed.
Explain how
assumeTrue and assumeFalse control test execution in JUnit.Think about when you want to skip tests instead of failing them.
You got /4 concepts.
Describe a real-life scenario where using
assumeTrue would be helpful in testing.Imagine you only want to run a test on Windows machines.
You got /3 concepts.