0
0
JUnittesting~10 mins

Verification times (times, never, atLeast) 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 verify that the method process() was called exactly once.

JUnit
verify(mockObject, [1]).process();
Drag options to blanks, or click blank then click option'
AatLeast(1)
Bnever()
Ctimes(1)
Dtimes(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using never() will check that the method was never called.
Using atLeast(1) allows one or more calls, not exactly one.
2fill in blank
medium

Complete the code to verify that the method save() was never called.

JUnit
verify(mockObject, [1]).save();
Drag options to blanks, or click blank then click option'
Anever()
Btimes(1)
CatLeast(1)
Dtimes(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using times(0) is similar but never() is clearer.
Using atLeast(1) would allow calls, which is incorrect here.
3fill in blank
hard

Fix the error in the verification to check that update() was called at least twice.

JUnit
verify(mockObject, [1]).update();
Drag options to blanks, or click blank then click option'
Atimes(2)
Bnever()
Ctimes(1)
DatLeast(2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using times(2) checks for exactly two calls, not at least two.
Using never() means no calls, which is wrong here.
4fill in blank
hard

Fill both blanks to verify that delete() was called exactly three times and create() was never called.

JUnit
verify(mockObject, [1]).delete();
verify(mockObject, [2]).create();
Drag options to blanks, or click blank then click option'
Atimes(3)
Bnever()
CatLeast(1)
Dtimes(1)
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up never() and times(0).
Using atLeast(1) instead of times(3) for exact calls.
5fill in blank
hard

Fill all three blanks to verify that start() was called at least once, stop() was called exactly twice, and reset() was never called.

JUnit
verify(mockObject, [1]).start();
verify(mockObject, [2]).stop();
verify(mockObject, [3]).reset();
Drag options to blanks, or click blank then click option'
AatLeast(1)
Btimes(2)
Cnever()
Dtimes(1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using times(1) instead of atLeast(1) for the start() method.
Confusing never() with times(0).