0
0
JUnittesting~10 mins

assertEquals 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 expected value equals the actual value using JUnit.

JUnit
assertEquals([1], actualValue);
Drag options to blanks, or click blank then click option'
A"expected"
BactualValue
CexpectedValue
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the actual value as the first argument instead of the expected value.
Using a variable that is not defined.
2fill in blank
medium

Complete the code to assert that two strings are equal in a JUnit test.

JUnit
assertEquals([1], "Hello World");
Drag options to blanks, or click blank then click option'
A"World"
B"Hello World"
C"Hello"
D"hello world"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with different case or spelling.
Swapping expected and actual values.
3fill in blank
hard

Fix the error in the assertion to correctly compare two integers.

JUnit
assertEquals([1], 5);
Drag options to blanks, or click blank then click option'
A5
B"5"
Cfive
D5.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "5" instead of integer 5.
Using a floating point number 5.0.
4fill in blank
hard

Fill both blanks to assert that the method returns the expected boolean value.

JUnit
assertEquals([1], [2]);
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
CisValid()
DcheckResult()
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping expected and actual values.
Using a method that does not return a boolean.
5fill in blank
hard

Fill all three blanks to assert that the method returns the expected string with a custom failure message.

JUnit
assertEquals([1], [2], [3]);
Drag options to blanks, or click blank then click option'
A"Expected greeting did not match"
BgetGreeting()
C"Hello, Tester!"
D"Greeting mismatch"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the message in the wrong position.
Swapping expected and actual values.