【发布时间】:2018-05-01 22:18:27
【问题描述】:
我想实现以下目标:
Class A{
List<Class B> list;
}
Class B{
}
@Mock
A a;
when(a.list.isEmpty()).then(true); // this throws an error
通过使用这个:
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
A a;
我必须使用吸气剂:
when(a.getList().isEmpty()).then(true);
但我不想更改我的代码以在任何地方使用 getter..
【问题讨论】:
-
恐怕你真的别无选择(除非你在某个时候做
a.list = mock(...);之类的事情)。 -
如果您希望列表为空以进行测试,那么您不能只使用一个空列表而不模拟任何内容吗?说真的,使用吸气剂。否则你会遇到比这更多的问题。
标签: java android unit-testing mocking mockito