Comments (12)
Released 1.5.4 should handle both your use-cases:
verifyAll { mock.call1() }
verify { mock wasNot Called }
Please check and close ticket if everything is OK
from mockk.
Hello. I have related problem.
I have mock with some methods. I want to be sure that method def will be called once and other methods will not be called:
verify(mock, only()).def()
verifyNoMoreInteractions(mock)
So i can't use solution of the issue:
//java.lang.AssertionError: Verification failed: Mock(#1) should not be called
verify(exactly = 1) { mock.def() }
verify { mock wasNot Called }
or
//java.lang.AssertionError: Verification failed: Mock(#1) should not be called
verifyAll { mock.def() }
verify { mock wasNot Called }
from mockk.
verifyNoMoreInteractions just finalizes un-ordered verification checks and verifies that nothing else was called except already verified. Basically in MockK DSL I have very similar construct verifySequence
, but it additionally checks order.
So overall solution would introduce verifyAll
following way:
verifyAll {
a.call1()
b.call2()
c.call3()
}
This translates to following Mockito code:
verify(a).call1()
verify(b).call2()
verify(c).call3()
verifyNoMoreInteractions(a, b, c)
Basically this checks that there was only calls 1,2 and 3 and nothing else in arbitrary order for mocks a, b and c.
Regarding verifyZeroIntercation
. My basic idea is following code:
verify {
a wasNot Called
}
but than logically to add was Called
verify {
a was Called
}
which means called some method at least once.
Then:
verify(atLeast = 5) {
a was Called
}
which means called some method at least 5 times.
Or:
verify(atMost = 5) {
a was Called
}
which means called some method at most 5 times.
And finally:
verifyOrder {
a was Called
b.def()
}
which means first some method of a
was called then method of b
called.
Similiar:
verifySequence {
a was Called
b.def()
}
which means first some method of a was called then method of b called and that is all interaction with mocks a
and b
.
Sorry for long read. I've checked the code and seems it requires few days/week effort to implement all that. I understand it's easy to just implement first two cases and other may be quite useless, but I need to think twice before starting.
from mockk.
Update: In case anyone tries to use verify { mock wasNot Called }
to replace verifyZeroInteractions()
but couldn't pass the test. The correct usage is confirmVerified(mock)
. See "Verification confirmation" section in https://mockk.io/
from mockk.
Check PR #2. You basically can verify call happened exactly 0 times
from mockk.
this works for verify(exactly = 0) { foo.bar() }
but it is not working for verify(exactly = 0) { foo }
similarly Mockito.verifyNoMoreInteractions(foo)
from mockk.
Ok, I'll consider adding it. Probably in today's night release
from mockk.
And thanks for reporting. Maybe any suggestions on how to do that? Anything else to add?
from mockk.
Thx.
I think it's worth to see how this is implemented in Mockito
I just started using mockk, maybe later there will be more requests
from mockk.
from mockk.
Mayde, something like
verifyNoMoreInteractions(foo, bar, ...)
or
verifyNoMoreInteractions {
foo
bar
...
}
from mockk.
Thx! I'll check it out soon
from mockk.
Related Issues (20)
- Allow to copy an existing mock HOT 1
- lateinit property has not been initialized on some ancestor classes HOT 2
- Using the result of callOriginal() inside coAnswers throws a fatal exception when the original contains a call to delay
- KotlinReflectionInternalError with HttpResponse.BodyHandler HOT 4
- Cannot create mock of interface, but of implementing class (method type parameters involved) HOT 2
- Error msg missing type information when no answers found for an overloaded method HOT 2
- kotlinx.datetime.Instant relaxed mock yields null java.time.Instant value
- NoSuchElementException in verify() HOT 3
- Bug: verify on anyConstructed<Mock>() throw an exception
- mockk-1.13.10 breaks tests that mock returning a value class HOT 2
- UInt properties cannot be mocked
- Poor performance with lateinit mockks
- Value class unboxing fails when mocked function and caller have the same name HOT 1
- mockkStatic/mockkObject not working HOT 2
- mockkObject not working in Maven
- Mockk deadlock during parallel tests
- Mocking doesn't work for a functional interface returning a value class
- Any.get() extension function is colliding with other classes extension function
- Can`t mock private property (Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock) HOT 1
- Cannot mock kotlin object's get property that returns value class
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockk.