0
0
JUnittesting~10 mins

assertDoesNotThrow 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 that the method does not throw any exception.

JUnit
assertDoesNotThrow(() -> [1]());
Drag options to blanks, or click blank then click option'
AfailTest
BthrowException
CmyMethod
DnullPointer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that actually throws an exception.
Not using a lambda expression.
Calling the method outside the lambda.
2fill in blank
medium

Complete the code to assert that the lambda expression does not throw an exception.

JUnit
assertDoesNotThrow([1]);
Drag options to blanks, or click blank then click option'
A() -> myMethod()
B() -> throwException()
CmyMethod()
DthrowException()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a method call directly instead of a lambda.
Using a method that throws an exception inside the lambda.
3fill in blank
hard

Fix the error in the assertion to correctly check no exception is thrown.

JUnit
assertDoesNotThrow(() -> [1]);
Drag options to blanks, or click blank then click option'
AmyMethod()
BmyMethod
CthrowException()
DthrowException
Attempts:
3 left
💡 Hint
Common Mistakes
Using method reference without parentheses inside the lambda.
Calling a method that throws an exception.
4fill in blank
hard

Fill both blanks to assert no exception is thrown when calling the method with arguments.

JUnit
assertDoesNotThrow(() -> [1]([2]));
Drag options to blanks, or click blank then click option'
AprocessData
B"input"
C42
DthrowException
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that throws an exception.
Passing an argument that is not a string literal.
5fill in blank
hard

Fill all three blanks to assert no exception is thrown when calling a method with two arguments.

JUnit
assertDoesNotThrow(() -> [1]([2], [3]));
Drag options to blanks, or click blank then click option'
AcalculateSum
B5
C10
DthrowException
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that throws exceptions.
Passing arguments in the wrong order.