Question

I have written one fixture:

!define TEST_SYSTEM {slim}
!path E:\eclipse\eclipse_workspace\FitnesseDemo\bin

Calculator Example

|com.example.qc.fixture.CalcFixture|
|pad1|pad2|margin1|margin2|get Padding?|get Margin?|
|7|8|8|8|25|26| 

In actual code I need to mock one third party class . (Delta) I have written the code for that, but how do I include that code in fitnesse.

I have created one SetUp page which contains the following:

!define TEST_SYSTEM {slim}
!path E:\eclipse\eclipse_workspace\FitnesseDemo\bin
!path E:\Docs\fitnesse\powermock-mockito-1.3.6-full.jar
!path E:\Docs\fitnesse\mockito-all.jar
!path E:\Docs\Junit\powermock-module-javaagent-1.4.10.jar

|Import|
|com.example.DeltaMock|

The mocked object is not getting called. Instead, the real object is getting called. Is my SetUp page code wrong?


First i tried to mock in CalcFixture , but it was always taking the real object . In calc fixture i have the follwing code

public int getPadding() throws Exception {

    Calc calc = new Calc();

    Delta ref = PowerMockito.mock(Delta.class);

    PowerMockito.whenNew(Delta.class).withNoArguments().thenReturn(ref);

    System.out.println("DeltaMocking.padding(rerf===  )" + ref);

    Mockito.stub(ref.padding()).toReturn(10);

    Padding = calc.addpadding(pad1, pad2);

    return Padding;

}

Addpadding method has the following code :

public int addpadding(int x, int y) {

    int k=0;

    Delta ref = new Delta();

    System.out.println("Calc.addpadding() refff="+ref);

    int z = ref.padding();

    k = x + y + z;

    return k;
}

Mocked object of Delta is never called.

Please help me through it ..

Était-ce utile?

La solution

Your Fitnesse test should not care if you are testing something with mock objects or real ones. All work is happen in the CalcFixture - this is where you should use Mockito to mock the object you need.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top