I have a following class in my project for which I am trying to write a test case
Class A{
a(){
B b = new B();
int ans = b.somefunction();
}
}
I need to mock somefunction() call in above class for my test
I tried following to achieve this
@RunWith(PowerMockRunner.class)
@PrepareForTest({A.class,B.class})
Class TestA{
testa(){
EasyMock mb = EasyMock.createMock(B.class);
PowerMock.createMock(B.class);
PowerMock.expectNew(B.class).andReturn(mb);
EasyMock.expect(mb.somefunction()).andReturn(0);
EasyMock.replay(mb);
PowerMock.replay(B.class);
}
}
but it always gives Java.lang.AssertionError: Unexpected method call B.somefunction()
I have PowerMock 1.5.5 and EasyMock 3.2 in my package
Can someone help me with the above problem and help me figure out where exactly I am going wrong. I am new to using EasyMock and PowerMock.
Does there exist a simpler way to test given class.
Aucun commentaire:
Enregistrer un commentaire