flutter_testmate 1.0.6
flutter_testmate: ^1.0.6 copied to clipboard
Testmate is a Flutter test utility package that provides a comprehensive suite of tools for testing and reporting Flutter applications.
Flutter TestMate π§ͺ #
flutter_testmate is a powerful Flutter integration testing toolkit and CLI utility that enhances the standard flutter_test experience.
It overrides the core testing functions β group, testWidgets, and expect β to provide richer reports, tag-based test filtering, and cleaner test syntax for Flutter Driver-style tests.
π Limitations of flutter drive #
- π« No built-in test reporting support
- π·οΈ Cannot run test cases based on tags or categories
π Solved with flutter_testmate #
The limitations of flutter driveβsuch as no built-in reporting and no tag-based test executionβare now a thing of the past! π
β¨ Features #
- π― Tag-based Test Filtering: Run specific tests using tags (e.g.,
smoke,regression) - π Rich HTML Reports: Beautiful, interactive test reports with detailed failure analysis
- π Safe Expect: Simplified test syntax with automatic error handling
- π·οΈ Test Suite Grouping: Organize tests with meaningful suite names
- π₯οΈ Flutter Driver Integration: Seamless integration with Flutter Driver
π Quick Start #
Installation #
Flutter TestMate is a CLI tool that can be installed from pub.dev:
- Install globally from pub.dev:
# Install the CLI tool globally
dart pub global activate flutter_testmate
Note: Make sure your pub global bin directory is in your PATH. If you get a "command not found" error, add this to your shell profile:
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export PATH="$PATH":"$HOME/.pub-cache/bin"
- Add to your project (for development):
# pubspec.yaml
dependencies:
flutter_testmate: ^1.0.0 # Use the latest version
Basic Usage #
- Create your integration test file (
integration_test/app.test.dart):- Make sure your files end with .test.dart
import 'package:flutter_test/flutter_test.dart' hide group, testWidgets, expect;
import 'package:integration_test/integration_test.dart';
import 'package:example/main.dart' as app;
import 'package:flutter_testmate/testmate.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Taxpayer Form Integration Tests', () {
testWidgets('Test 1: Should enter text in PAN field',
(WidgetTester tester) async {
// Start the app
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
// Simplified syntax - just use expect() directly!
expect(find.text('First Name'), findsOneWidget);
expect(find.text('Middle Name'), findsOneWidget);
// Record test result and fail if needed
SafeExpect.failIfAnyFailed();
});
testWidgets('Should have form elements',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
expect(find.text('First Name'), findsOneWidget);
expect(find.text('Middle Name'), findsOneWidget);
SafeExpect.failIfAnyFailed();
});
});
group('Another Group', () {
testWidgets('Test Case One',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
expect(find.text('First Name'), findsOneWidget);
expect(find.text('Middle Name'), findsOneWidget);
SafeExpect.failIfAnyFailed();
});
testWidgets('Test Case Two',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 2));
expect(find.text("Dashboard"), findsOneWidget);
SafeExpect.failIfAnyFailed();
}, tags: ['smoke']); // Tagged test
});
// Print and save all test results as JSON at the end
tearDownAll(() {
SafeExpect.printAndSaveTestResults();
});
}
- Run tests:
# Run all tests
flutter_testmate test
# Run tests on web
flutter_testmate test --web
π·οΈ Tag-based Test Filtering #
Flutter TestMate supports powerful tag-based test filtering to run specific subsets of your tests:
Adding Tags to Tests #
testWidgets('Critical login test',
(WidgetTester tester) async {
// Test implementation
}, tags: ['smoke', 'critical']);
testWidgets('Regression test for payment flow',
(WidgetTester tester) async {
// Test implementation
}, tags: ['regression', 'payment']);
Running Tagged Tests #
# Run smoke tests
flutter_testmate test --tag smoke
# Run regression tests
flutter_testmate test --tag regression
# Run critical tests
flutter_testmate test --tag critical
How Tag Filtering Works #
- Scans all
.test.dartfiles in theintegration_testdirectory - Finds tests with the specified tag
- Creates a temporary filtered test file (e.g.,
smoke_test.dart) - Runs only the tagged tests
- Cleans up the temporary file automatically
π Test Reports #
Flutter TestMate generates comprehensive test reports in multiple formats:
HTML Report #
The HTML report provides a beautiful, interactive interface showing:
- Test Summary: Total tests, passed, failed counts
- Test Suites: Organized by groups with proper naming
- Individual Test Results: Detailed status and timing
- Failure Analysis: Stack traces and error details
- Responsive Design: Works on desktop and mobile
Report Location: testmate-reports/safeexpect_report.html
Report Screenshot
The HTML report features a modern, clean design with comprehensive test analytics:

Key Features:
- π Test Summary Dashboard: Shows pass rate (75.0%), total tests (4), passed (3), failed (1)
- π Visual Progress Bar: Green progress bar indicating test completion status
- π― Test Suite Organization: Tests grouped by meaningful suite names
- β Detailed Error Analysis:
- Clickable error messages with line numbers
- Stack trace viewing capability
- File path references for easy debugging
- β Status Indicators: Color-coded pills (green for passed, red for failed)
- π± Responsive Design: Clean, modern interface that works on all devices
- π Timestamp Information: Shows when the report was generated
Interactive Elements:
- Expandable error details: Click to view full stack traces
- File navigation: Direct links to error locations in your code
- Collapsible test suites: Organize large test suites efficiently
JSON Report #
Machine-readable test results for CI/CD integration:
{
"testSuites": [
{
"testSuite": "Taxpayer Form Integration Tests",
"testWidgets": [
{
"testName": "Test 1: Should enter text in PAN field",
"testSuite": "Taxpayer Form Integration Tests",
"expectFailed": [],
"status": "Passed",
"timestamp": "2025-10-16T18:21:37.151"
}
]
}
],
"summary": {
"totalTests": 4,
"passedTests": 3,
"failedTests": 1
}
}
Report Location: testmate-reports/report.json
π§ Configuration #
CLI Options #
flutter_testmate test [options]
Options:
-w, --web Run on Flutter Web
-t, --tag <tag> Run only tests with specific tag (e.g., @smoke)
-h, --help Show help information
Usage Examples #
# Basic usage
flutter_testmate test
# Run on web
flutter_testmate test --web
# Run specific tagged tests
flutter_testmate test --tag smoke
# Run tagged tests on web
flutter_testmate test --web --tag regression
# Get help
flutter_testmate --help
Test File Structure #
integration_test/
βββ app.test.dart # Main test file
βββ login.test.dart # Additional test file
βββ smoke_test.dart # Generated filtered test (temporary)
βββ regression_test.dart # Generated filtered test (temporary)
testmate-reports/
βββ report.json # JSON test results
βββ safeexpect_report.html # HTML test report
π οΈ Advanced Usage #
Custom Test Suites #
Tests are automatically grouped by their group() name, which becomes the test suite name in reports:
group('Payment Flow Tests', () {
// All tests in this group will be under "Payment Flow Tests" suite
testWidgets('Credit card payment', (tester) async {
// Test implementation
});
});
Error Handling #
Flutter TestMate provides automatic error handling with SafeExpect:
// Old way (manual error handling)
try {
expect(find.text('Button'), findsOneWidget);
} catch (e) {
// Handle error
}
// New way (automatic error handling)
expect(find.text('Button'), findsOneWidget); // Errors are caught automatically
SafeExpect.failIfAnyFailed(); // Fail the test if any expects failed
Multiple Test Files #
You can have multiple test files in the integration_test directory:
integration_test/
βββ app.test.dart
βββ login.test.dart
βββ payment.test.dart
βββ user_profile.test.dart
All files ending with .test.dart will be scanned for tag filtering.
π± Example Project #
The included example project demonstrates:
- Basic integration tests with form validation
- Tagged tests for different test categories
- Multiple test groups with proper suite naming
- Error handling and failure reporting
- Real Flutter app integration
Running the Example #
# First, install the package
dart pub global activate flutter_testmate
# Navigate to your project directory
cd your-flutter-project
# Run all tests
flutter_testmate test
# Run tests on web
flutter_testmate test --web
# Run only smoke tests
flutter_testmate test --tag smoke
# Run smoke tests on web
flutter_testmate test --web --tag smoke
π€ Contributing #
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Made with β€οΈ for the Flutter community