A. assertEquals is used incorrectly without expected value.
B. Static import of assumptions is missing.
C. The test method must return a boolean.
D. assumeTrue requires a boolean condition argument.
Solution
Step 1: Check assumeTrue usage
assumeTrue() is called without any argument, but it requires a boolean condition.
Step 2: Verify other parts
assertEquals(5, 2 + 3); is correct; static import is present.
Final Answer:
assumeTrue requires a boolean condition argument. -> Option D
Quick Check:
assumeTrue(condition) needs argument [OK]
Hint: assumeTrue always needs a boolean argument [OK]
Common Mistakes:
Calling assumeTrue without argument
Confusing assumeTrue with assertTrue
Ignoring compiler errors on missing argument
5.
You want to write a JUnit test that only runs on Linux systems and skips on others. Which code snippet correctly uses assumeTrue or assumeFalse to achieve this?
hard
A. assumeTrue(System.getProperty("os.name").startsWith("Linux"));
B. assumeFalse(System.getProperty("os.name").startsWith("Linux"));
C. assumeTrue(!System.getProperty("os.name").startsWith("Linux"));
D. assumeFalse(!System.getProperty("os.name").startsWith("Linux"));
Solution
Step 1: Define the condition for Linux
The test should run only if the OS name starts with "Linux".
Step 2: Use assumeTrue with Linux condition
assumeTrue(System.getProperty("os.name").startsWith("Linux")); runs the test only on Linux, skips otherwise.
Final Answer:
assumeTrue(System.getProperty("os.name").startsWith("Linux")); -> Option A
Quick Check:
Run only if Linux = assumeTrue(Linux) [OK]
Hint: Use assumeTrue with positive condition to run test [OK]
Common Mistakes:
Using assumeFalse with Linux condition incorrectly
Negating condition wrongly
Confusing assumeTrue and assumeFalse logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.