JMock允许其他方法调用 [英] JMock Allow Other Method Calls
本文介绍了JMock允许其他方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用JMock来测试使用对象的类的行为.我想测试方法a()
是否被调用.但是,b()
和c()
也会在对象上被调用.因此,如果我的期望值是a()
,则它也必须期望b()
和c()
才能通过测试.有没有一种方法可以只测试某种方法,并允许其他任何方法?
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?
推荐答案
期望a()
仅允许方法b()
& c()
Expect a()
allow only methods b()
& c()
mockery.checking(new Expectations() {{
one(mockObject).a();
allowing(mockObject).b();
allowing(mockObject).c();
}});
期望a()
允许所有其他方法.
Expect a()
allow all other methods.
mockery.checking(new Expectations() {{
one(mockObject).a();
allowing(mockObject);
}});
这篇关于JMock允许其他方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文