question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have Mockito.once to simplify Mockito.times(1)

See original GitHub issue

Most verification counts in Tests are Mockito.times(1). Having a handly Mockito.once() would simplify the test and make them more readable.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
iherasymenkocommented, Feb 4, 2021

How about Mockito.verify(mock).method(something) ? Imo this is a reasonable alternative that has been available for a while.

0reactions
TimvdLippecommented, Dec 16, 2021

Closing this issue for now. Given that the default behavior of Mockito.verify is to imply times(1), omitting the VerificationMode is better than adding a new alias for it.

Thanks everyone for your contributions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito: How to verify a method was called only once with ...
This simplification does provide value if you are primarily concerned with minimizing character count. However the accepted Answer has value too, in that...
Read more >
A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Mockito requires you to provide all arguments either by matchers or by exact values. So if a method has more than one argument...
Read more >
Clean Unit Tests with Mockito - Reflectoring
In this article we will learn how to mock objects with Mockito. We'll first talk about what test doubles are and then how...
Read more >
Mockito (Mockito 4.9.0 API) - javadoc.io
The Mockito library enables mock creation, verification and stubbing. This javadoc content is also available on the https://site.mockito.org/ web page.
Read more >
Mockito Verify - DigitalOcean
Above verify method will pass if add("Pankaj") is called only once on the mocked list object. It's the same as calling with times(1)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found