Skip to content

Commit

Permalink
Merge pull request #279 from jonsamwell/test-compatibility
Browse files Browse the repository at this point in the history
Make it possible to run the tests with flutter test instead of flutter drive.
  • Loading branch information
jonsamwell authored Dec 26, 2022
2 parents 7c8be5f + e8c874f commit 8f34c82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ targets:
# Allows the code generator to target files outside of the lib folder
- integration_test/**.dart
```
3. Add the following file (and folder) `\test_driver\integration_test_driver.dart`. This file is the entry point to run your tests. See `https://flutter.dev/docs/testing/integration-tests` for more information.
3. Add the following file (and folder) `\test_driver\integration_test_driver.dart`. This file is the entry point to run your tests.
If you want ot use the flutter test command approach, you will not need this file (and be unused when it is created).
See `https://flutter.dev/docs/testing/integration-tests` for more information.
```dart
import 'package:integration_test/integration_test_driver.dart' as integration_test_driver;
Expand Down Expand Up @@ -83,25 +85,23 @@ import 'package:example_with_integration_test/main.dart' as app;
part 'gherkin_suite_test.g.dart';
@GherkinTestSuite()
void main() {
executeTestSuite(
FlutterTestConfiguration.DEFAULT([])
..reporters = [
StdoutReporter(MessageLevel.error)
..setWriteLineFn(print)
..setWriteFn(print),
ProgressReporter()
..setWriteLineFn(print)
..setWriteFn(print),
TestRunSummaryReporter()
..setWriteLineFn(print)
..setWriteFn(print),
JsonReporter(
writeReport: (_, __) => Future<void>.value(),
),
],
(World world) => app.main(),
@GherkinTestSuite(
featurePaths: <String>['integration_test/features/**.feature'],
executionOrder: ExecutionOrder.sequential)
Future<void> main() async {
var configuration = FlutterTestConfiguration(
reporters: [
TestRunSummaryReporter(),
JsonReporter(
writeReport: (_, __) => Future<void>.value(),
),
],
);
await executeTestSuite(
configuration: configuration,
appMainFunction: (World world) async => app.main(),
);
}
```
Expand All @@ -114,6 +114,14 @@ flutter pub run build_runner build
```
flutter drive --driver=test_driver/integration_test_driver.dart --target=integration_test/gherkin_suite_test.dart
```

If you do not want to use the flutter drive command, but the flutter test command you need to change some aspects.
It is REQUIRED that in `integration_test\gherkin_suite_test.dart` the executeTestSuite is awaited.
And then you can run your test command:
```
flutter test integration_test/gherkin_suite_test.dart
```

10. You can debug the tests by adding a breakpoint to line 12 in `integration_test\gherkin_suite_test.dart` and adding the below to your `.vscode\launch.json` file:
```json
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
{{feature_functions}}
}
void executeTestSuite({
Future<void> executeTestSuite({
required FlutterTestConfiguration configuration,
required StartAppFn appMainFunction,
Timeout scenarioExecutionTimeout = const Timeout(const Duration(minutes: 10)),
AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
}) {
_CustomGherkinIntegrationTestRunner(
}) =>
_CustomGherkinIntegrationTestRunner(
configuration: configuration,
appMainFunction: appMainFunction,
appLifecyclePumpHandler: appLifecyclePumpHandler,
Expand Down

0 comments on commit 8f34c82

Please sign in to comment.