所以,我正在尝试测试我的颤振应用程序。这是我所做的
class MockSplashScreenBloc extends MockBloc<SplashScreenState>
implements SplashScreenBloc {}
void main() {
MockSplashScreenBloc splashScreenBloc;
Widget MyWidget() {
return MaterialApp(
home: BlocProvider(
create: (context) {
return SplashScreenBloc(url: "google.com");
},
child: SplashScreen(),
),
);
}
group('Splash Screen Widget Test', () {
setUp(() {
splashScreenBloc = MockSplashScreenBloc();
});
tearDown(() {
splashScreenBloc?.close();
});
testWidgets('should render Container when state is Default State',
(WidgetTester tester) async {
when(splashScreenBloc.state).thenAnswer((_) => Default());
await tester.pumpWidget(MyWidget());
expect(find.byKey(ValueKey("container_empty")), findsOneWidget);
});
testWidgets('should render LoadingIndicator when state is Loading State',
(WidgetTester tester) async { …Run Code Online (Sandbox Code Playgroud)