A Flutter package for running performance tests and generating detailed performance reports. This package helps developers analyze their app's performance metrics, including CPU usage, memory usage, widget build times, and frame rendering metrics.
- Collects performance data using Flutter's integration test framework.
- Generates detailed markdown reports with performance metrics.
- Provides suggestions for performance improvements based on collected data.
- Supports custom performance baselines for tailored analysis.
The Performance Driver package offers two versions for running performance tests:
-
flutter_driver:
- Uses the legacy
flutter_driver
package. - Suitable for apps that are not yet migrated to the new integration testing framework.
- Provides a more traditional approach to UI testing.
- Uses the legacy
-
integration_test:
- Utilizes the newer
integration_test
package. - Recommended for new projects as it offers better performance and more features.
- Supports more advanced testing scenarios and improved reporting.
- Utilizes the newer
Feature | flutter_driver | integration_test |
---|---|---|
Testing Framework | Legacy flutter_driver |
New integration_test |
Performance Reporting | Basic reporting capabilities | Detailed markdown reports |
Test Execution | Slower due to legacy architecture | Faster and more efficient |
API Support | Limited to older APIs | Full support for new APIs |
Community Support | Less active | Actively maintained and updated |
To use the Performance Driver package, follow these steps:
-
Add the dependency to your
pubspec.yaml
file:dependencies: perf_driver: ^0.0.1
-
Import the package in your Dart file:
import 'package:perf_driver/perf_driver.dart';
-
Run performance tests by creating a sample driver file in your project.
To run performance tests, you can use the perfDriver
function. Here’s an example of how to set it up:
import 'package:flutter/material.dart';
import 'package:perf_driver/perf_driver.dart';
void main() {
perfDriver();
// Or with custom baselines:
// perfDriver(customBaselines: PerformanceBaselines(...));
}
You can wrap your integration test with the runPerformanceTest
method to generate a performance report:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:perf_driver/src/perf_src.dart';
Future<void> main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('MyApp Tests', (tester) async {
await runPerformanceTest(
'My Performance Test',
testWidget: MyApp(),
tester: tester,
callback: (binding, tester) async {
// Interact with your app here
await tester.pumpAndSettle();
},
);
});
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Performance Test')),
body: Center(child: Text('Hello, World!')),
),
);
}
}
For more information on how to contribute to the package, file issues, or find more resources, please refer to the Dart documentation and the Flutter documentation.
This package is licensed under the MIT License. See the LICENSE file for more details.