簡體   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