0
0
JUnittesting~10 mins

Testing no exception thrown 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 no exception is thrown when calling the method.

JUnit
assertDoesNotThrow(() -> [1]());
Drag options to blanks, or click blank then click option'
AfailMethod
BthrowException
CerrorMethod
DmyMethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that throws an exception inside assertDoesNotThrow.
Forgetting the lambda syntax and writing method call directly.
2fill in blank
medium

Complete the code to test that no exception is thrown when executing the runnable.

JUnit
assertDoesNotThrow([1]);
Drag options to blanks, or click blank then click option'
A() -> runnable.run()
Bnew Runnable()
Crunnable.run()
Drunnable
Attempts:
3 left
💡 Hint
Common Mistakes
Passing runnable.run() directly, which executes immediately.
Passing the runnable object instead of a lambda.
3fill in blank
hard

Fix the error in the test code to correctly assert no exception is thrown.

JUnit
assertDoesNotThrow(() -> [1].execute());
Drag options to blanks, or click blank then click option'
Atask
Bnull
C123
DSystem
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null causing NullPointerException.
Passing a number or class instead of an object.
4fill in blank
hard

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

JUnit
assertDoesNotThrow(() -> [1].[2](input));
Drag options to blanks, or click blank then click option'
Aservice
Bprocess
Cexecute
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping object and method names.
Using methods that do not accept the input argument.
5fill in blank
hard

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

JUnit
assertDoesNotThrow(() -> [1].[2]([3]));
Drag options to blanks, or click blank then click option'
AUtils
B"test"
CrunTask
D123
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string argument.
Calling instance methods on a class name.