我正在尝试测试一个使用配置单元库存储数据的数据库类。
我写了这个代码测试:
// import ...
import 'my_datasource_hive_test.mocks.dart';
@GenerateNiceMocks([
MockSpec<BoxCollection>()
])
void main() {
test(
'MyDatasourceHive Constructor',
() {
// Assign
final mockMyCollection = MockBoxCollection();
final datasource = MyDatasourceHive(
collection: mockMyCollection,
);
},
);
然后运行生成MockBoxCollection类的命令:flutter pub run build_runner build
当我运行测试时,我有下一个错误:The parameter 'boxCreator' of the method 'MockBoxCollection.openBox' has type 'CollectionBox/*1*/<V> Function(String, BoxCollection)?', which does not match the corresponding type, 'CollectionBox/*2*/<V> Function(String, BoxCollection)?', in the overridden method, 'BoxCollection.openBox'.
1条答案
按热度按时间vd2z7a6w1#
您收到的错误表明
MockBoxCollection.openBox
和BoxCollection.openBox
中的参数不匹配。请尝试以下操作:flutter pub upgrade mockito
命令更新mokito软件包。MockBoxCollection
以匹配BoxCollection
接口。