jeudi 23 juillet 2015

Using Mockito to mock a class method inside another class

I'm trying to write unit tests with Mockito / JUnit for a function like this:

class1 {
 method {
  object1 = class2.method // method that I want to fake the return value
  // some code that I still want to run
 }
}

Is there any way in Mockito to stub the result of class2.method? I'm trying to improve code coverage for class1 so I need to call its real production methods.

I looked into the Mockito API at its spy method but that would overwrite the whole method and not the part that I want.

Aucun commentaire:

Enregistrer un commentaire