From ef04fa338678ffb59833ebf6affdff2189a8a21c Mon Sep 17 00:00:00 2001 From: Jon Samwell Date: Thu, 21 Jan 2021 15:41:24 +1100 Subject: [PATCH] fix(integration_test): ensure tearDownAll is always run --- CHANGELOG.md | 3 +++ .../integration_test/features/create.feature | 3 ++- .../integration_test/gherkin/configuration.dart | 3 ++- .../gherkin/reports/integration_response_data.json | 2 +- .../gherkin/steps/when_step_has_timeout.dart | 12 ++++++++++++ .../runners/gherkin_integration_test_runner.dart | 4 ++-- 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 example_with_integration_test/integration_test/gherkin/steps/when_step_has_timeout.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 87d09ce..4ea64c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,9 @@ flutter drive --driver=test_driver/integration_test_driver.dart --target=integra 11. Custom world need to extend `FlutterWorld` note `FlutterDriverWorld`. 12. If you change any of the feature files you will need to re-generate the tests using the below command ``` +# you might need to run the clean command first if you have just changed feature files +flutter pub run build_runner clean + flutter pub run build_runner build ``` diff --git a/example_with_integration_test/integration_test/features/create.feature b/example_with_integration_test/integration_test/features/create.feature index ffe36b1..ff7afd8 100644 --- a/example_with_integration_test/integration_test/features/create.feature +++ b/example_with_integration_test/integration_test/features/create.feature @@ -22,4 +22,5 @@ Feature: Creating todos | Buy blueberries | | Buy apples | | Buy carrots | - Given I wait 5 seconds for the animation to complete \ No newline at end of file + Given I wait 5 seconds for the animation to complete + When I test the default step timeout is not applied to step with custom timeout \ No newline at end of file diff --git a/example_with_integration_test/integration_test/gherkin/configuration.dart b/example_with_integration_test/integration_test/gherkin/configuration.dart index 1e6f632..722f129 100644 --- a/example_with_integration_test/integration_test/gherkin/configuration.dart +++ b/example_with_integration_test/integration_test/gherkin/configuration.dart @@ -8,6 +8,7 @@ import 'package:gherkin/gherkin.dart'; import 'hooks/reset_app_hook.dart'; import 'steps/expect_todos_step.dart'; import 'steps/when_await_animation.dart'; +import 'steps/when_step_has_timeout.dart'; import 'world/custom_world.dart'; FlutterTestConfiguration gherkinTestConfiguration = @@ -15,6 +16,7 @@ FlutterTestConfiguration gherkinTestConfiguration = [ thenIExpectTheTodos, whenAnAnimationIsAwaited, + whenStepHasTimeout, ], ) // ..tagExpression = '@debug' @@ -35,7 +37,6 @@ FlutterTestConfiguration gherkinTestConfiguration = writeReport: (_, __) => Future.value(), ), ] - ..defaultTimeout = const Duration(minutes: 1) ..createWorld = (config) => Future.value(CustomWorld()); void Function(World) appInitializationFn = (World world) { diff --git a/example_with_integration_test/integration_test/gherkin/reports/integration_response_data.json b/example_with_integration_test/integration_test/gherkin/reports/integration_response_data.json index 934ebc3..048f1f3 100644 --- a/example_with_integration_test/integration_test/gherkin/reports/integration_response_data.json +++ b/example_with_integration_test/integration_test/gherkin/reports/integration_response_data.json @@ -1,3 +1,3 @@ { - "gherkin_reports": "[[{\"description\":\"\",\"id\":\"creating todos:\",\"keyword\":\"Feature\",\"line\":1,\"name\":\"Creating todos:\",\"uri\":\"\",\"tags\":[{\"line\":1,\"name\":\"@tag\"}],\"elements\":[{\"keyword\":\"Scenario\",\"type\":\"scenario\",\"id\":\"creating todos:;user can create a new todo item\",\"name\":\"User can create a new todo item\",\"description\":\"\",\"line\":1,\"tags\":[{\"line\":1,\"name\":\"@tag\"},{\"line\":1,\"name\":\"@tag1\"},{\"line\":1,\"name\":\"@tag_two\"}],\"steps\":[{\"keyword\":\"Given \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy carrots\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":516000000}},{\"keyword\":\"When \",\"name\":\"I tap the 'add' button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":534000000}},{\"keyword\":\"Then \",\"name\":\"I expect the todo list\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":157000000},\"rows\":[{\"cells\":[\"Todo\"]},{\"cells\":[\"Buy carrots\"]}]}]},{\"keyword\":\"Scenario\",\"type\":\"scenario\",\"id\":\"creating todos:;user can create multiple new todo items\",\"name\":\"User can create multiple new todo items\",\"description\":\"\",\"line\":1,\"tags\":[{\"line\":1,\"name\":\"@tag\"},{\"line\":1,\"name\":\"@debug\"}],\"steps\":[{\"keyword\":\"Given \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy carrots\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":371000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":496000000}},{\"keyword\":\"And \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy apples\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":269000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":500000000}},{\"keyword\":\"And \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy blueberries\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":258000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":480000000}},{\"keyword\":\"Then \",\"name\":\"I expect the todo list\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":382000000},\"rows\":[{\"cells\":[\"Todo\"]},{\"cells\":[\"Buy blueberries\"]},{\"cells\":[\"Buy apples\"]},{\"cells\":[\"Buy carrots\"]}]},{\"keyword\":\"Given \",\"name\":\"I wait 5 seconds for the animation to complete\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":122000000}}]}]}]]" + "gherkin_reports": "[[{\"description\":\"\",\"id\":\"creating todos:\",\"keyword\":\"Feature\",\"line\":1,\"name\":\"Creating todos:\",\"uri\":\"\",\"tags\":[{\"line\":1,\"name\":\"@tag\"}],\"elements\":[{\"keyword\":\"Scenario\",\"type\":\"scenario\",\"id\":\"creating todos:;user can create a new todo item\",\"name\":\"User can create a new todo item\",\"description\":\"\",\"line\":1,\"tags\":[{\"line\":1,\"name\":\"@tag\"},{\"line\":1,\"name\":\"@tag1\"},{\"line\":1,\"name\":\"@tag_two\"}],\"steps\":[{\"keyword\":\"Given \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy carrots\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":506000000}},{\"keyword\":\"When \",\"name\":\"I tap the 'add' button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":510000000}},{\"keyword\":\"Then \",\"name\":\"I expect the todo list\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":143000000},\"rows\":[{\"cells\":[\"Todo\"]},{\"cells\":[\"Buy carrots\"]}]}]},{\"keyword\":\"Scenario\",\"type\":\"scenario\",\"id\":\"creating todos:;user can create multiple new todo items\",\"name\":\"User can create multiple new todo items\",\"description\":\"\",\"line\":1,\"tags\":[{\"line\":1,\"name\":\"@tag\"},{\"line\":1,\"name\":\"@debug\"}],\"steps\":[{\"keyword\":\"Given \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy carrots\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":360000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":480000000}},{\"keyword\":\"And \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy apples\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":265000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":468000000}},{\"keyword\":\"And \",\"name\":\"I fill the \\\"todo\\\" field with \\\"Buy blueberries\\\"\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":259000000}},{\"keyword\":\"When \",\"name\":\"I tap the \\\"add\\\" button\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":483000000}},{\"keyword\":\"Then \",\"name\":\"I expect the todo list\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":392000000},\"rows\":[{\"cells\":[\"Todo\"]},{\"cells\":[\"Buy blueberries\"]},{\"cells\":[\"Buy apples\"]},{\"cells\":[\"Buy carrots\"]}]},{\"keyword\":\"Given \",\"name\":\"I wait 5 seconds for the animation to complete\",\"line\":1,\"match\":{\"location\":\":1\"},\"result\":{\"status\":\"passed\",\"duration\":130000000}}]}]}]]" } \ No newline at end of file diff --git a/example_with_integration_test/integration_test/gherkin/steps/when_step_has_timeout.dart b/example_with_integration_test/integration_test/gherkin/steps/when_step_has_timeout.dart new file mode 100644 index 0000000..14e540b --- /dev/null +++ b/example_with_integration_test/integration_test/gherkin/steps/when_step_has_timeout.dart @@ -0,0 +1,12 @@ +import 'package:gherkin/gherkin.dart'; +import 'package:flutter_gherkin/flutter_gherkin_integration_test.dart'; +import 'package:flutter_test/flutter_test.dart'; + +final whenStepHasTimeout = when( + 'I test the default step timeout is not applied to step with custom timeout', + (_) async { + await Future.delayed(const Duration(seconds: 30)); + }, + configuration: StepDefinitionConfiguration() + ..timeout = const Duration(seconds: 15), +); diff --git a/lib/src/flutter/runners/gherkin_integration_test_runner.dart b/lib/src/flutter/runners/gherkin_integration_test_runner.dart index 1529e39..32a035d 100644 --- a/lib/src/flutter/runners/gherkin_integration_test_runner.dart +++ b/lib/src/flutter/runners/gherkin_integration_test_runner.dart @@ -54,13 +54,13 @@ abstract class GherkinIntegrationTestRunner { _safeInvokeFuture(() async => await reporter.onTestRunStarted()); - onRun(); - tearDownAll( () { onRunComplete(); }, ); + + onRun(); } void onRun();