0
0
JUnittesting~10 mins

Single assertion per test debate 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 sum of 2 and 3 equals 5.

JUnit
assertEquals([1], 2 + 3);
Drag options to blanks, or click blank then click option'
A4
B6
C5
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong expected value in the assertion.
2fill in blank
medium

Complete the code to assert that a string is not null.

JUnit
assertNotNull([1]);
Drag options to blanks, or click blank then click option'
AsomeString
B""
C"hello"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a literal null or string literal instead of a variable.
3fill in blank
hard

Fix the error in the assertion that checks if two objects are equal.

JUnit
assertEquals([1], expectedObject, actualObject);
Drag options to blanks, or click blank then click option'
A"message"
BexpectedObject
CactualObject
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping expected and actual arguments.
Passing objects in wrong order.
4fill in blank
hard

Fill both blanks to create a test that asserts a list contains exactly 3 elements and is not empty.

JUnit
assertEquals([1], myList.size());
assertFalse([2]);
Drag options to blanks, or click blank then click option'
A3
BmyList.isEmpty()
CmyList.size() == 3
DmyList.isEmpty() == false
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect expressions inside assertions.
Confusing assertFalse with assertTrue.
5fill in blank
hard

Fill all three blanks to write a test that asserts a string is not null, contains 'test', and has length 4.

JUnit
assertNotNull([1]);
assertTrue([2]);
assertEquals([3], [1].length());
Drag options to blanks, or click blank then click option'
AinputString
BinputString.contains("test")
C4
DinputString.length()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or literals.
Mixing up length checks and contains checks.