dart 抛出了以下消息:在运行当前测试期间检测到多个异常(2),其中至少有一个异常是意外的

ffscu2ro  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(86)

在小部件测试中的Flutter。每次我面对这个问题
我有疑问的方法,以直接小部件等待测试。pumpWidget(用户详细信息();

void main() {
  var emailField = find.byKey(Key("fname-field"));
  var passwordField = find.byKey(Key("lname-field"));
  var passwordField1 = find.byKey(Key("enumber-field"));
  var signInButton = find.text("SUBMIT");
  group("UserDetails  Screen test", () {
    testWidgets("Check the buttons in User screen",
        (WidgetTester tester) async {
      await tester.pumpWidget(  UserDetails()
      );
      await tester.pump();
      expect(emailField, findsOneWidget);
      expect(passwordField, findsOneWidget);
      expect(signInButton, findsOneWidget);
      expect(passwordField1, findsOneWidget);
    });
  });
}

这里出现了如下错误
Flutter测试框架捕获的异常情况抛出以下消息:在当前测试运行期间检测到多个异常(2),并且至少有一个异常是意外的。
附加到呈现树时引发以下FirebaseException:[core/no-app]未创建Firebase应用程序“[DEFAULT]”-调用Firebase.initializeApp()

cdmah0mi

cdmah0mi1#

看起来你在页面被打开之前就试着找到小部件了。
按如下方式更改范围:

void main() {
  group("UserDetails  Screen test", () {
    testWidgets("Check the buttons in User screen",
        (WidgetTester tester) async {
      await tester.pumpWidget(UserDetails());
      await tester.pumpAndSettle();
      await tester.pump();

      var emailField = find.byKey(Key("fname-field"));
      var passwordField = find.byKey(Key("lname-field"));
      var passwordField1 = find.byKey(Key("enumber-field"));
      var signInButton = find.text("SUBMIT");

      expect(emailField, findsOneWidget);
      expect(passwordField, findsOneWidget);
      expect(signInButton, findsOneWidget);
      expect(passwordField1, findsOneWidget);
    });
  });
}

相关问题