0
0
JUnittesting~10 mins

assertTrue and assertFalse in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assert that the condition is true.

JUnit
assert[1](isValid);
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CEquals
DNull
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertFalse instead of assertTrue
Using assertEquals for boolean conditions
2fill in blank
medium

Complete the code to assert that the condition is false.

JUnit
assert[1](isEmpty);
Drag options to blanks, or click blank then click option'
ATrue
BNotNull
CFalse
DSame
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertTrue instead of assertFalse
Using assertNull for boolean checks
3fill in blank
hard

Fix the error in the assertion method to check if the user is logged in.

JUnit
assert[1](user.isLoggedIn());
Drag options to blanks, or click blank then click option'
ANotEquals
BFalse
CNull
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertFalse which expects false condition
Using assertNull which is for null checks
4fill in blank
hard

Fill both blanks to assert that the list is empty and the flag is false.

JUnit
assert[1](list.isEmpty());
assert[2](flag);
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CEquals
DNull
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping assertTrue and assertFalse
Using assertEquals for boolean checks
5fill in blank
hard

Fill all three blanks to assert that the user is active, the count is zero, and the error flag is false.

JUnit
assert[1](user.isActive());
assertEquals([2], count);
assert[3](errorFlag);
Drag options to blanks, or click blank then click option'
ATrue
B0
CFalse
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong assertion methods for boolean checks
Using wrong expected value in assertEquals