I'm trying to use widget test for my project and test works fine till reach the point I use an http request in the actual page and it ,I think, ignore the request
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}),
);
the account.body returns empty while it works well during using the emulator
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, "[email protected]");
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);
});
});
I am not sure if I missed something I'm still beginner
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…