0
0
JUnittesting~5 mins

assumeTrue and assumeFalse in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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 Windows
Click to reveal answer
What does assumeTrue(false) do in a JUnit test?
AFails the test
BThrows an exception
CSkips the test
DPasses the test
Which method skips a test if the condition is true?
AassumeTrue
BassumeFalse
CassertTrue
DassertFalse
When should you use assumptions in tests?
ATo check if test conditions are met before running
BTo fail tests on errors
CTo log test results
DTo assert expected output
What is the difference between assumeTrue and assertTrue?
ABoth skip test if false
BassumeTrue fails test if false; assertTrue skips test if false
CBoth fail test if false
DassumeTrue skips test if false; assertTrue fails test if false
If an assumption fails, what is the test status?
ASkipped
BFailed
CPassed
DError
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.