在flutter integration_testing 中是否有更好的方法来测试具有多个测试数据的简单登录功能,而不是为不同的测试数据集编写不同的测试用例。
测试用例:
'成功登录/注销'
'使用空的用户名和密码登录'
'只用空密码登录'
'仅使用空用户名登录'
'使用无效用户名、有效密码登录'
'使用无效密码登录,有效用户名'
以下尝试的方法涉及在测试用例中重复的大量冗余代码库?
void main() async {
setUpAll(() {});
setUp(() {});
tearDownAll(() {});
tearDown(() {});
//Initialize page objects
LoginScreenPage loginScreenPage;
ProjectScreenPage projectScreenPage;
FloorEditorScreenPage floorEditorScreenPage;
group('BICS Complete E2E Test', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding;
testWidgets('Successful Login/Logout', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
const username = 'gorike8673@d3bb.com';
const password = '1qaZ2wsX';
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.enterUsernameAndPassword(
username: username, password: password);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.byIcon(Icons.logout),
timeout: const Duration(seconds: 5));
expect(find.byIcon(Icons.logout), findsOneWidget);
await loginScreenPage.clickLogoutButton();
await CommonUtils.pumpUntilFound(tester, find.text('Username'),
timeout: const Duration(seconds: 5));
expect(find.text('Username'), findsOneWidget);
},);
testWidgets('Login with empty Username and Password',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.text('Failed'),
timeout: const Duration(seconds: 5));
expect(find.text('Failed'), findsOneWidget);
});
testWidgets('Login with only Password empty', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
const username = 'gorike8673@d3bb.com';
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.enterUsernameAndPassword(username: username);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.text('Failed'),
timeout: const Duration(seconds: 5));
expect(find.text('Failed'), findsOneWidget);
});
testWidgets('Login with only Username empty', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
const password = '1qaZ2wsX';
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.enterUsernameAndPassword(password: password);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.text('Failed'),
timeout: const Duration(seconds: 5));
expect(find.text('Failed'), findsOneWidget);
});
testWidgets('Login with invalid username, valid password',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
const username = 'gorike8673';
const password = '1qaZ2wsX';
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.enterUsernameAndPassword(
username: username, password: password);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.text('Failed'),
timeout: const Duration(seconds: 5));
expect(find.text('Failed'), findsOneWidget);
});
testWidgets('Login with invalid password, valid username',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
const username = 'gorike8673@d3bb.com';
const password = '1qaZ';
final loginScreenPage = LoginScreenPage(tester);
await loginScreenPage.enterUsernameAndPassword(
username: username, password: password);
await loginScreenPage.clickLoginButton();
await CommonUtils.pumpUntilFound(tester, find.text('Failed'),
timeout: const Duration(seconds: 5));
expect(find.text('Failed'), findsOneWidget);
});});}