Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在玩 Mockito (1.9.5) 并停留在第一个简单的测试用例:
List mockedList = mock(ArrayList.class); assertEquals(0, mockedList.size()); // Passed assertTrue(mockedList.isEmpty()); // Failed
谁能解释为什么这里 isEmpty() 返回 false 而 size() 返回 0?
我认为这是因为 mockito 不isEmpty()知道false. 同样的想法也会发生,size()但这里的默认值为0.
isEmpty()
false
size()
0
基本上,您需要定义模拟对象的预期行为。如果不这样做,它将返回默认值。