我正在尝试对我的项目使用小部件测试,并且测试工作正常,直到达到我在实际页面中使用 http 请求的程度,我认为,忽略该请求
final account = await http.post(
'http://10.0.2.2:5000/LogIn',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: json.encode({'email': email, 'password': password}),
);
account.body 在使用模拟器期间运行良好时返回空
testWidgets("Successful Sign In", (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: SignIn()));
//1-find widgets needed
final textfieldemail = find.byKey(Key("emailtextformfield"));
expect(textfieldemail, findsOneWidget);
final textfieldpassword = find.byKey(Key("passwordtextformfield"));
expect(textfieldpassword, findsOneWidget);
final buttonsignin = find.byKey(Key("Signin"));
expect(buttonsignin, findsOneWidget);
//2-execute the actual test
await tester.enterText(textfieldemail, "Weaam.wewe91@gmail.com");
await tester.enterText(textfieldpassword, "Weaam@91");
await tester.tap(buttonsignin);
await tester.pump(Duration(seconds: 5));
//await tester.pump(Duration(seconds: 5));
//await _navigateToAccountHome(tester);
//3-check results
expect(find.byType(DeliveryHome), findsOneWidget);
});
});
我不确定我是否错过了什么我还是初学者