JMock Allow Other Method Calls

2019-02-23 03:48发布

I'm using JMock to test the behavior of a class using an object. I want to test that the method a() is called. However, b() and c() also are called on the object too. Therefore if my expectations expect a(), it must also expect b() and c() to make the test pass. Is there a way to test only for a certain method, and allow anything else?

1条回答
We Are One
2楼-- · 2019-02-23 04:26

Expect a() allow only methods b() & c()

mockery.checking(new Expectations() {{
    one(mockObject).a();

    allowing(mockObject).b();
    allowing(mockObject).c();
}});

Expect a() allow all other methods.

mockery.checking(new Expectations() {{
    one(mockObject).a();

    allowing(mockObject);
}});
查看更多
登录 后发表回答