Skip to content

Verification on mock object not respect to test case #74

@mesut

Description

@mesut

Problem:

Let's say we have two different service

class ServiceA(serviceB: ServiceB) {

  def methodA(): String = {
    "methodA called"
    serviceB.methodB()
  }

  def methodA2(): String = {
    "methodA2 called"
    serviceB.methodB()
  }
}

I write two test method and try to verify methodB called or not. When I run two test cases separately, tests pass. When I run all test methods, verification gives wrong result for second test.
In test class context, mockito-verification records all calls on mock object. I think mockito-scala should reset verification counts on mock objects after each test

class ServiceATest extends FlatSpec with IdiomaticMockito {
  val serviceB: ServiceB = mock[ServiceB]
  val serviceA: ServiceA = new ServiceA(serviceB)
  "methodA" should "called" in {
    serviceA.methodA()
    serviceB.methodB wasCalled once // Passes
  }
  "methodA2" should "called" in {
    serviceA.methodA2()
    serviceB.methodB wasCalled once // Fail. it was 2 times:
  }
}

Btw I tried with mockito-core, it gives same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions