Powermock - how to mock a specific method and leave the rest of the object as-is

后端 未结 1 1766
清酒与你
清酒与你 2021-01-24 02:16

I have a Person class with get set for FirstName, LastName

A TestClass to execute TestCase1

Can we just only mock a specific method (getLastName) and leave every

1条回答
  •  隐瞒了意图╮
    2021-01-24 02:45

    You can use spy to mock individual (including private) methods:

    Person classUnderTest = PowerMockito.spy(new Person());
    
        // use PowerMockito to set up your expectation
        PowerMockito.doReturn("Fixed value").when(classUnderTest, "getLastName");
    

    0 讨论(0)
提交回复
热议问题