我正在使用flutter_bloc、bloc_test 和bloc_testing 来实现测试。但即使在我在设置中初始化 Bloc 之后,错误也会说 Null 检查运算符用于空值。
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:orotask/logic/bloc/map_bloc/map_bloc.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:orotask/logic/repository/addr_map_repository.dart';
class MockAddrRepository extends Mock implements MapAddrRepository {}
void main()async {
late MapAddrRepository mapAddrRepository ;
late MapBloc mapBloc;
await Firebase.initializeApp();
setUp(() {
mapAddrRepository = MapAddrRepository();
mapBloc = MapBloc();
});
tearDown(() {
mapBloc.close();
});
blocTest<MapBloc, MapState>('Map Bloc Initial State Tests',
build: () => mapBloc,
expect: () => MapNotLoaded());
}
错误flutter test --no-sound-null-safety
(我有一些不支持空安全的依赖项)
00:20 +0 -1: loading C:\Users\Dell\Desktop\OroTask\orotask\test\src\bloc\visit_bloc\visit_bloc_test.dart [E]
Failed to load "C:\Users\Dell\Desktop\OroTask\orotask\test\src\bloc\visit_bloc\visit_bloc_test.dart": Null check operator used on a null value
package:flutter/src/services/platform_channel.dart 142:86 MethodChannel.binaryMessenger
package:flutter/src/services/platform_channel.dart 148:36 MethodChannel._invokeMethod
package:flutter/src/services/platform_channel.dart 331:12 MethodChannel.invokeMethod
package:flutter/src/services/platform_channel.dart 344:41 MethodChannel.invokeListMethod
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 30:37 MethodChannelFirebase._initializeCore
package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart 77:13 MethodChannelFirebase.initializeApp
package:firebase_core/src/firebase.dart 41:47 Firebase.initializeApp
test\src\bloc\visit_bloc\visit_bloc_test.dart
14:18