0
0
JUnittesting~10 mins

Why assertions verify expected outcomes in JUnit - Test Your Understanding

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'
A5
B7
C4
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong expected value like 6 or 4.
Confusing actual and expected values.
2fill in blank
medium

Complete the code to assert that the string "hello" starts with "he".

JUnit
assertTrue("hello".[1]("he"));
Drag options to blanks, or click blank then click option'
AendsWith
BstartsWith
Ccontains
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using endsWith instead of startsWith.
Using equals which checks full string equality.
3fill in blank
hard

Fix the error in the assertion that checks if a list is empty.

JUnit
assertTrue([1].isEmpty());
Drag options to blanks, or click blank then click option'
AmyList.get(0)
BmyList.size()
CmyList
DmyList.isEmpty
Attempts:
3 left
💡 Hint
Common Mistakes
Calling isEmpty on size() or get(0) which are not boolean methods.
Using isEmpty without parentheses.
4fill in blank
hard

Fill both blanks to assert that the multiplication of 4 and 5 equals 20.

JUnit
assertEquals([1], [2] * 5);
Drag options to blanks, or click blank then click option'
A4
B20
C6
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 20 as the first blank and 20 as the second blank causing wrong multiplication.
Using 6 or 3 which do not produce 20 when multiplied by 5.
5fill in blank
hard

Fill all three blanks to assert that the substring "test" is contained in "unittesting".

JUnit
assertTrue("unittesting".[1]([2].[3]()));
Drag options to blanks, or click blank then click option'
Acontains
B"test"
CtoString
DstartsWith
Attempts:
3 left
💡 Hint
Common Mistakes
Using startsWith instead of contains.
Not converting the substring to string before checking.