繁体   English   中英

flutter 集成测试使用新的 integration_test package 测试异常时出错

[英]Error for flutter integration test using the new integration_test package to test exceptions

我正在编写一个集成测试来尝试在我的代码中捕获异常,但我有点卡在我的代码出错的地方。 如果您有任何想法,请告诉我:-)

以下是我的代码;

Future<Null> _signInPageUnrecognizedEmailProvided(

    WidgetTester tester) async {
  await tester
      .pumpAndSettle(Duration(seconds: reasonableStartupTimeInSeconds));

  expect(emailFormField, findsOneWidget);
  expect(passwordFormField, findsOneWidget);
  expect(loginButton, findsOneWidget);

  await tester.enterText(emailFormField, unrecognizedUsername);
  await tester.enterText(passwordFormField, validPassword);
  await tester.pumpAndSettle();

  await tester.tap(loginButton);

  await tester.pumpAndSettle(
      Duration(seconds: reasonableAuthenticationTimeInSeconds));

  expect(tester.takeException(), isInstanceOf<HandledException>());

  tester.resetTestTextInput();
}

这是我的错误;

I/flutter (22131): 💡  Router - generateRoute | name: LoginView arguments: null
I/flutter (22131): ⚠️  AuthenticationApiService - The user name or password is incorrect. If you have not registered, please use
the Register New Account link below.
I/flutter (22131): ⛔  LogService - identifier: AuthenticationService.getAndStoreAuthToken | exception: The user name or password
is incorrect. If you have not registered, please use the Register New Account link below. | displayMessage: The user name or      
password is incorrect. If you have not registered, please use the Register New Account link below. | alertView: AlertView.Dialog |{email: d.sillyname@smartspaces.app}
I/flutter (22131): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (22131): The following TestFailure object was thrown running a test:
I/flutter (22131):   Expected: <Instance of 'HandledException'>
I/flutter (22131):   Actual: <null>
I/flutter (22131):    Which: is not an instance of 'HandledException'
I/flutter (22131):
I/flutter (22131): When the exception was thrown, this was the stack:
I/flutter (22131): #4      main.<anonymous closure>._signInPageUnrecognizedEmailProvided```

似乎您来自 emailFormField 和 passFormField 的输入条目没有被注册,并且正在返回 null 值。

预期:<'HandledException' I/flutter 的实例(22131):实际:null

结果,身份验证失败,这导致了错误。 检查有关如何在 email / 密码字段中输入值的代码,并定向进行身份验证。 这可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM