我目前在编写一个测试,用于输入不匹配的密码信息,以检查我们的AlertDialog小部件是否显示文本:“密码不匹配!”
以下是我的AlertDialog所在位置:
以下是我的AlertDialog所在位置:
if (passwordController.text != reenterController.text) {
showDialog(
context: context,
builder: (context) {
return const AlertDialog(
key: Key('signUpADKey'),
content: Text('Passwords do not match!'),
);
},
);
}
值得注意的是,这个if语句位于ElevatedButton的onPressed()
部分。
此外,以下为我的测试:
testWidgets('Miss-matching Passwords Test', (WidgetTester tester) async {
SignUpPage page = SignUpPage();
await tester.pumpWidget(makeTestableApp(page));
await tester.enterText(
find.byKey(const Key('firstNameTextFormField')), 'Jimmy');
await tester.enterText(
find.byKey(const Key('lastNameTextFormField')), 'Lewis');
await tester.enterText(find.byKey(const Key('shortBioTextFormField')),
'I go to the University of ABC.');
await tester.enterText(
find.byKey(const Key('emailTextFormField')), 'jimmylewis@abc.edu');
await tester.enterText(
find.byKey(const Key('passwordTextFormField')), 'Test1234!');
await tester.enterText(
find.byKey(const Key('reEnterTextFormField')), 'Test4321!');
await tester.pump();
await tester.tap(find.text('Sign Up'));
await tester.pump();
expectLater(find.byKey(const Key('signUpADKey')), findsOneWidget);
});