问题描述
我正在尝试使用JMockit模拟集合中项目的行为。说,我想在2号页面中测试对象。我可以创建Injectables并将其添加到如下集合中:
@Injectable PageItem item0;
@Injectable PageItem item1;
@Injectable PageItem item2;
new Expectations() {{
item0.getPage();
result=1;
item1.getPage();
result=1;
item2.getPage();
result=2;
}}
Collection<PageItem> mockItems = Arrays.asList(item0,item1,item2);
assertthat(item0,is(onPage(1)));
assertthat(item1,is(onPage(1)));
assertthat(item2,is(onPage(2)));
如果我想编写具有动态项目数的通用测试,是否可以动态填充mockItems
集合?
Mockito为我提供了一种通过提供模拟程序的编程工厂来实现这一目标的方法:
PageItem mock = mock(PageItem.class);
然后我可以在需要的多次迭代中调用此方法,同时注入基于索引的行为。
什么是JMockit等效项?还是有另一种测试方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)