Have Mockito.once to simplify Mockito.times(1)
See original GitHub issueMost 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:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How about
Mockito.verify(mock).method(something)
? Imo this is a reasonable alternative that has been available for a while.Closing this issue for now. Given that the default behavior of
Mockito.verify
is to implytimes(1)
, omitting the VerificationMode is better than adding a new alias for it.Thanks everyone for your contributions!