0
0
JUnittesting~10 mins

assertNull and assertNotNull 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 check if the object is null using JUnit.

JUnit
[1](myObject);
Drag options to blanks, or click blank then click option'
AassertEquals
BassertNotNull
CassertNull
DassertTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertNotNull instead of assertNull.
Using assertEquals which requires two parameters.
2fill in blank
medium

Complete the code to check if the object is not null using JUnit.

JUnit
[1](user);
Drag options to blanks, or click blank then click option'
AassertNotNull
BassertFalse
CassertNull
DassertSame
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertNull instead of assertNotNull.
Using assertFalse which expects a boolean condition.
3fill in blank
hard

Fix the error in the assertion to check that the variable is null.

JUnit
[1](expectedValue, actualValue);
Drag options to blanks, or click blank then click option'
AassertNull
BassertNotNull
CassertEquals
DassertTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertNull with two parameters causes a compile error.
Confusing assertNull with assertEquals.
4fill in blank
hard

Fill both blanks to assert that the object is not null and provide a failure message.

JUnit
[1]("Object should not be null", [2]);
Drag options to blanks, or click blank then click option'
AassertNotNull
BassertNull
CmyObject
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertNull instead of assertNotNull.
Passing null instead of the object variable.
5fill in blank
hard

Fill all three blanks to assert that the user object is null with a custom message.

JUnit
[1]("User must be null", [2]); // Check user
// Next, assert that the session is not null
[3](session);
Drag options to blanks, or click blank then click option'
AassertNull
Buser
CassertNotNull
Dsession
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up assertNull and assertNotNull.
Passing wrong variables to assertions.