Trackmart uses multiple testing frameworks to ensure code quality and functionality. The testing setup includes unit tests, widget tests, and integration tests.
test/ directory contains unit and widget tests that run in the Flutter test environment.test_driver/ directory contains integration tests that run against a real app instance.
// Find by textfind.text('Trackmart')// Find by keyfind.byKey(Key('request'))// Find by widget typefind.byType(ElevatedButton)// Find by iconfind.byIcon(Icons.add)
// Tap a widgetawait tester.tap(find.byKey(Key('request')));await tester.pump();// Enter textawait tester.enterText(find.byType(TextField), 'Hello');await tester.pump();// Scrollawait tester.drag( find.byType(ListView), Offset(0, -300));await tester.pump();
The test_driver/app.dart:1-11 file sets up the app for driver testing:
test_driver/app.dart
import 'package:flutter_driver/driver_extension.dart';import 'package:sandtrack/main.dart' as app;void main() { // This line enables the extension enableFlutterDriverExtension(); // Call the `main()` function of your app or call `runApp` with any widget you // are interested in testing. app.main();}
This file enables the Flutter Driver extension, allowing the test runner to communicate with the app.
Gherkin allows you to write tests in a human-readable format:
Feature: Order Delivery Scenario: User requests delivery Given I am on the request page When I enter quantity "5" And I tap the "Request" button Then I should see a confirmation dialog
Feature: Order Management Scenario: Request sand delivery Given I have the app open When I tap the "Request" tab And I enter quantity "5" And I select unit "Tonne" Then I should see the calculated price
3
Implement Step Definitions
Create step definitions that map to your Gherkin steps.
testWidgets('displays data after loading', (WidgetTester tester) async { await tester.pumpWidget(MyApp()); // Show loading state expect(find.byType(CircularProgressIndicator), findsOneWidget); // Wait for async operation await tester.pumpAndSettle(); // Verify loaded state expect(find.text('Data Loaded'), findsOneWidget);});
testWidgets('submits form with valid data', (WidgetTester tester) async { await tester.pumpWidget(MyApp()); // Enter text in fields await tester.enterText(find.byKey(Key('quantity')), '5'); await tester.pump(); // Submit form await tester.tap(find.byKey(Key('submit'))); await tester.pumpAndSettle(); // Verify result expect(find.text('Success'), findsOneWidget);});