doNothing() cannot be used on suspend Unit functions
See original GitHub issueMocking Unit method where the first call should doNothing()
and then 2nd doThrow()
, produces the following error:
Only void methods can doNothing()!
Example:
doNothing().doThrow(RuntimeException::class.java).whenever(mock).foo()
where foo()
is suspend fun foo()
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Non-void method with doNothing() in Mockito? - Stack Overflow
The create() method is not void, so you cannot mock it with doNoting() so you have to use doReturn instead. In you case...
Read more >Mockito 2.3.4 API - javadoc.io
Mockito verifies argument values in natural java style: by using an equals() method. Sometimes, when extra flexibility is required then you might use...
Read more >`when` and `do*` | Migrating from Mockito | MockK Guidebook
Answer only contains a single method, so Kotlin allows a function literal to be used instead through SAM conversion. val mockedFile = mock(File::class.java) ......
Read more >Mockito 2.2.7 API
The Mockito library enables mock creation, verification and stubbing. This javadoc content is also available on the http://mockito.org web page.
Read more >Mocking/stubbing stuff near the "bottom of the pile"...
Since touching a real database is not a unit test anymore, personally I prefer not to do just "hibernate tests" if not necessary....
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
@iadcialim You can use
which does not execute
functionReturningUnit()
aswould.
@nhaarman In my case, when a suspend function of a mocked or spied object is called, I don’t want it to do whatever it has inside. So its like doNothing but that now for functions that return a Unit. But now it does not work as specified above. Any workaround for this?