Set value to mocked object but get null

后端 未结 6 667
无人共我
无人共我 2021-02-12 22:31

I have a simple class Foo to be mocked:

public class Foo {
   private String name;
   public Foo() {
   }
   public Foo(String name) {
     this.nam         


        
6条回答
  •  一向
    一向 (楼主)
    2021-02-12 22:53

    To solve your problem of knowing whether the setName() method was called in your code with the specified value use the Mockito verify method.

    For example:

    verify(mockedFoo, times(1)).setName("test");
    

    Will verify that the mockedFoo.setName() method with the String parameter "test" was called exactly once in the code under test.

提交回复
热议问题