
Organizing your test suites efficiently is crucial for maintaining a clean, scalable, and maintainable test architecture, especially when using Patrol, a robust mobile testing framework. One effective strategy is to group tests by screen name, allowing you to organize tests into directories that correspond to the screens in your app. This practice not only improves clarity but also makes it easier for your QA team to locate and maintain specific test cases as your project evolves.

Get Access to the Test App & Framework
Pro Members unlock hands-on access to our expertly crafted frameworks.
Organizing Tests by Screen Name
When testing a mobile application, screens often represent a core aspect of the user flow. Each screen might have different behaviors, elements, and functionalities that require unique test cases. By organizing tests by screen name, you ensure that:
- Tests are easily navigable: Team members can quickly find tests related to specific app screens.
- Reusability and maintenance are enhanced: Updates to screens or features can be isolated to relevant directories without impacting the entire test suite.
- Collaboration is smoother: Teams can focus on specific screens without having to comb through large, unrelated test files.
Create Screen-Specific Directories
In Patrol, you can organize your tests into directories that correspond to specific screens in your app. The following structure is an example:
integration_test/
└── e2e/
├── dashboard/
│ └── dashboard_test.dart
├── menu/
│ └── menu_test.dart
├── notifications/
│ └── notifications_test.dart
├── profile/
│ └── profile_test.dart
├── sign_in/
│ └── sign_in_test.dart
└── sign_up/
└── sign_up_test.dart
Each directory contains the relevant test files for that particular screen. This keeps the tests clean and organized. Here’s how each folder corresponds to the app:
-
dashboard/
: Tests focused on ensuring the functionality of the user dashboard. -
menu/
: Tests for menu navigation, clicking and validating the menu items. -
notifications/
: Tests to verify the functionality of the notification screen. -
profile/
: Tests centered on user profile management, and updating personal details. -
sign_in/
: Tests for the sign-in screen, focusing on logging in and error handling. -
sign_up/
: Tests for the sign-up screen, ensuring registration is working as expected.
Writing Tests for Each Screen
Let’s dive deeper into crafting a sample test for the dashboard screen. This test suite will encompass various tests to ensure that essential elements are displayed correctly, including the Dashboard title, key transfer functions such as Deposit, Withdraw, Send, and Request, as well as the transaction history components.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';
import 'package:richpay_app/main.dart' as app;
void main() {
patrolTest(
'Dashboard Screen - Verify the elements on the dashbaord',
($) async {
// Start the app
app.main();
await $.pumpAndTrySettle();
final welcomeSignInButton = $(find.byKey(const Key('sign_in_btn')));
await $(welcomeSignInButton).tap();
await $.pumpAndSettle();
// // Verify the presence of email/username input field and enter text
final emailTextBox = $(find.byKey(const Key('email_username')));
await $(emailTextBox).enterText('test@gmail.com');
final passwordTextBox = $(find.byKey(const Key('password')));
await $(passwordTextBox).enterText('test123');
final signInSignInButton = $(find.byKey(const Key('sign_in_btn')));
await $(signInSignInButton).tap();
// Wait for the navigation to complete after sign-in
await $.pumpAndSettle();
// Add further assertions if needed
expect(find.text('Dashboard'), findsOneWidget);
expect(find.text('Deposit'), findsAtLeast(1));
expect(find.text('Withdraw'), findsOneWidget);
expect(find.text('Send'), findsOneWidget);
expect(find.text('Request'), findsOneWidget);
expect(find.text('Transactions History'), findsOneWidget);
},
);
}
Naming Conventions and Test Flow
Using consistent naming conventions is essential. Screen directories and test files should be named based on the screens they test. This eliminates confusion, especially as your test suite grows. For example:
- dashboard_test.dart: Tests related to the dashboard screen.
- profile_test.dart: Tests related to the profile screen.
When writing these tests, ensure that:
- Each test is self-contained: A test should not rely on another test. This enhances the modularity of your test suite.
- Each test function should clearly describe the functionality being tested, such as
verify_profile_update
ortest_sign_up_with_invalid_credentials
.
Running Tests by Directory
Patrol allows you to run tests for a specific directory if you want to focus on tests for a particular screen. Here’s how to run tests for the sign_in
screen using the CLI:
patrol test -t integration_test/e2e/sign_in/
Tip: Running On IOS?
If you’re running your Patrol test on an iOS device, make sure to pass the
-d
flag followed by the device’s UDID. This ensures that the correct device is targeted and avoids any running issues that could occur if it’s omitted. For example:
patrol test -d D76D6C18-03AE-46E0-A732-C46608EBF212 -t integration_test/e2e/sign_in
In this command, D76D6C18-03AE-46E0-A732-C46608EBF212
is the UDID of your iOS device, and the -t
flag is used to specify the test file, such as integration_test/e2e/sign_in
.
This command will execute all tests within the sign_in
directory, making it easy to target specific areas of the app without running the entire test suite.
Conclusion
Organizing test suites by screen name in Patrol helps maintain clean, efficient, and scalable test cases. By creating screen-specific directories, you enhance collaboration and streamline the testing process. This structure becomes especially helpful as your app grows and new features are added. Following this organization strategy ensures that your tests are well-structured, easy to manage, and scalable for future updates.
In the next lesson, we’ll dive deeper into Organizing Test Suites by Screen Name in Patrol, where you’ll learn how to effectively categorize your tests and maintain a robust testing workflow.