Git Product home page Git Product logo

Comments (12)

oleksiyp avatar oleksiyp commented on May 15, 2024 17

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.

prestuhome avatar prestuhome commented on May 15, 2024 6

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.

oleksiyp avatar oleksiyp commented on May 15, 2024 3

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.

shiehnpin avatar shiehnpin commented on May 15, 2024 1

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.

oleksiyp avatar oleksiyp commented on May 15, 2024

Check PR #2. You basically can verify call happened exactly 0 times

from mockk.

alexxxdev avatar alexxxdev commented on May 15, 2024

this works for verify(exactly = 0) { foo.bar() }
but it is not working for verify(exactly = 0) { foo } similarly Mockito.verifyNoMoreInteractions(foo)

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

Ok, I'll consider adding it. Probably in today's night release

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

And thanks for reporting. Maybe any suggestions on how to do that? Anything else to add?

from mockk.

alexxxdev avatar alexxxdev commented on May 15, 2024

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.

oleksiyp avatar oleksiyp commented on May 15, 2024

from mockk.

alexxxdev avatar alexxxdev commented on May 15, 2024

Mayde, something like
verifyNoMoreInteractions(foo, bar, ...)
or

verifyNoMoreInteractions {
   foo
   bar
   ...
}

from mockk.

alexxxdev avatar alexxxdev commented on May 15, 2024

Thx! I'll check it out soon

from mockk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.