- 2023-06-25mockito5.4.0单元测试(9) --调用同一个方法和参数依次返回不同的值thenReturn和thenThrow
mockito官方文档地址:https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#exact_verification//mock一个对象ListsingleMock=mock(List.class);when(singleMock.get(20)).thenThrow(newRuntimeException())//mock第一次调用
- 2023-06-21mockito5.4.0单元测试(8) --验证某个方法从未被调用
mockito官方文档地址:https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#30 //usingmocks-onlymockOneisinteractedmockOne.add("one");//ordinaryverificationverify(mockOne).add("one"); //验证调用过addon
- 2023-06-20mockito5.4.0单元测试(5) --校验mock对象的某种方法的准确调用次数
mokito官方文档地址:https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#exact_verification//mock一个对象LinkedListmockedList=mock(LinkedList.class);//使用mock对象来操作mockedList.add("once");//添加"once"一次
- 2023-06-19mockito5.4.0单元测试(4) --主动throw异常,模拟异常处理
importstaticorg.mockito.Mockito.*; //引入类 LinkedListmockedList=mock(LinkedList.class); //获得mock对象 //stubbingwhen(mockedList.get(0)).thenReturn("first"); //如果获取0索引,则返回:first when(mockedList.get(1)).the
- 2023-06-19mockito5.4.0单元测试(1) 官方文档地址
mockito官方文档地址:https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html end.