feat(integration_test): more progress with reporting

This commit is contained in:
Jon Samwell 2021-01-08 17:20:30 +11:00
parent 7dc4408f62
commit cf8d28d63e
12 changed files with 143 additions and 56 deletions

View File

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]}],"date_created":"2021-01-08 11:27:21.268830","version":"1.22.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Google\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\integration_test-1.0.1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]}],"date_created":"2021-01-08 16:39:37.431562","version":"1.22.5"}

View File

@ -55,7 +55,18 @@ part 'gherkin_suite_test.g.dart';
@GherkinTestSuite()
void main() {
executeTestSuite(
FlutterTestConfiguration.DEFAULT([]),
FlutterTestConfiguration.DEFAULT([])
..reporters = [
StdoutReporter(MessageLevel.error)
..setWriteLineFn(print)
..setWriteFn(print),
ProgressReporter()
..setWriteLineFn(print)
..setWriteFn(print),
TestRunSummaryReporter()
..setWriteLineFn(print)
..setWriteFn(print),
],
app.main,
);
}

View File

@ -1,3 +1,3 @@
{
"gherkin_results": "{\"test\":\"moo\"}"
"gherkin_results": "{\"test\":\"moo1\"}"
}

View File

@ -1,6 +1,11 @@
Feature: Counter
@tag1 @tag_two
Scenario: User can increment the counter
Given I expect the "counter" to be "0"
When I tap the "increment" button
Then I expect the "counter" to be "1"
Then I expect the "counter" to be "1"
Given the table
| Header One | Header Two | Header Three |
| 1 | 2 | 3 |
| 4 | 5 | 6 |

View File

@ -0,0 +1,11 @@
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
StepDefinitionGeneric givenTheTable() {
return given1<Table, FlutterWorld>(
'the table',
(table, context) async {
// do something with the table data
},
);
}

View File

@ -5,12 +5,27 @@ import 'package:gherkin/gherkin.dart';
// The application under test.
import 'package:example_with_integration_test/main.dart' as app;
import 'gherkin/steps/table_step.dart';
part 'gherkin_suite_test.g.dart';
@GherkinTestSuite()
void main() {
executeTestSuite(
FlutterTestConfiguration.DEFAULT([]),
FlutterTestConfiguration.DEFAULT([
givenTheTable(),
])
..reporters = [
StdoutReporter(MessageLevel.error)
..setWriteLineFn(print)
..setWriteFn(print),
ProgressReporter()
..setWriteLineFn(print)
..setWriteFn(print),
TestRunSummaryReporter()
..setWriteLineFn(print)
..setWriteFn(print),
],
app.main,
);
}

View File

@ -21,16 +21,10 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
group(
'Counter:',
() {
testWidgets(
runScenario(
'User can increment the counter',
(WidgetTester tester) async {
final dependencies = await createTestDependencies(
configuration,
tester,
);
await startApp(tester);
['@tag1', '@tag_two'],
(TestDependencies dependencies) async {
await runStep(
'Given I expect the "counter" to be "0"',
[],
@ -52,9 +46,14 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
dependencies,
);
cleanupScenarioRun(dependencies);
await runStep(
'Given the table',
[],
Table.fromJson(
'[{"Header One":"1","Header Two":"2","Header Three":"3"},{"Header One":"4","Header Two":"5","Header Three":"6"}]'),
dependencies,
);
},
timeout: scenarioExecutionTimeout,
);
},
);

View File

@ -235,8 +235,8 @@ packages:
dependency: transitive
description:
path: "."
ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
resolved-ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
ref: "80c03137d883637b2526e16a945009d76c3cbd85"
resolved-ref: "80c03137d883637b2526e16a945009d76c3cbd85"
url: "https://github.com/jonsamwell/dart_gherkin.git"
source: git
version: "1.1.10"

View File

@ -130,21 +130,12 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor {
}
''';
static const String SCENARIO_TEMPLATE = '''
testWidgets(
runScenario(
'{{scenario_name}}',
(WidgetTester tester) async {
final dependencies = await createTestDependencies(
configuration,
tester,
);
await startApp(tester);
{{tags}},
(TestDependencies dependencies) async {
{{steps}}
cleanupScenarioRun(dependencies);
},
timeout: scenarioExecutionTimeout,
);
''';
static const String STEP_TEMPLATE = '''
@ -197,13 +188,12 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor {
}
@override
Future<void> visitScenario(
String name,
Iterable<String> tags
) async {
Future<void> visitScenario(String name, Iterable<String> tags) async {
_flushScenario();
_currentScenarioCode =
_replaceVariable(SCENARIO_TEMPLATE, 'scenario_name', name);
_currentScenarioCode =
_replaceVariable(_currentScenarioCode, 'tags', '[${tags.map((e) => "'$e'").join(', ')}]');
}
@override
@ -221,7 +211,7 @@ class FeatureFileTestGeneratorVisitor extends FeatureFileVisitor {
code = _replaceVariable(
code,
'step_table',
'null',
table == null ? 'null' : 'Table.fromJson(\'${table.toJson()}\')',
);
_stepBuffer.writeln(code);

View File

@ -7,11 +7,11 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
class _TestDependencies {
class TestDependencies {
final World world;
final AttachmentManager attachmentManager;
_TestDependencies(
TestDependencies(
this.world,
this.attachmentManager,
);
@ -25,6 +25,8 @@ abstract class GherkinIntegrationTestRunner {
Iterable<ExecutableStep> _executableSteps;
Iterable<CustomParameter> _customParameters;
IntegrationTestWidgetsFlutterBinding _binding;
Reporter get reporter => _reporter;
Hook get hook => _hook;
@ -46,28 +48,82 @@ abstract class GherkinIntegrationTestRunner {
}
Future<void> run() async {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
_binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding;
try {
await _reporter.onTestRunStarted();
onRun();
} finally {
_safeInvokeFuture(() async => await reporter.onTestRunFinished());
_safeInvokeFuture(() async => await _hook.onAfterRun(configuration));
_safeInvokeFuture(() async => await reporter.dispose());
setTestResultData(binding);
}
await _reporter.onTestRunStarted();
onRun();
tearDownAll(() {
onRunComplete();
});
}
void onRun();
void onRunComplete() {
_safeInvokeFuture(() async => await reporter.onTestRunFinished());
_safeInvokeFuture(() async => await hook.onAfterRun(configuration));
setTestResultData(_binding);
_safeInvokeFuture(() async => await reporter.dispose());
}
void setTestResultData(IntegrationTestWidgetsFlutterBinding binding) {
binding.reportData = {
'gherkin_results': jsonEncode({'test': 'moo'})
'gherkin_results': jsonEncode({'test': 'moo1'})
};
}
@protected
void runScenario(
String name,
Iterable<String> tags,
Future<void> Function(TestDependencies dependencies) runTest,
) {
testWidgets(
'User can increment the counter',
(WidgetTester tester) async {
final debugInformation = RunnableDebugInformation('', 0, name);
final scenarioTags =
(tags ?? Iterable<Tag>.empty()).map((t) => Tag(t, 0));
final dependencies = await createTestDependencies(
configuration,
tester,
);
await startApp(tester);
await reporter.onScenarioStarted(
StartedMessage(
Target.scenario,
name,
debugInformation,
scenarioTags,
),
);
await runTest(dependencies);
await _reporter.onScenarioFinished(
ScenarioFinishedMessage(
name,
debugInformation,
true,
),
);
await _hook.onAfterScenario(
configuration,
name,
scenarioTags,
);
cleanupScenarioRun(dependencies);
},
timeout: scenarioExecutionTimeout,
);
}
@protected
Future<void> startApp(WidgetTester tester) async {
appMainFunction();
@ -75,7 +131,7 @@ abstract class GherkinIntegrationTestRunner {
}
@protected
Future<_TestDependencies> createTestDependencies(
Future<TestDependencies> createTestDependencies(
TestConfiguration configuration,
WidgetTester tester,
) async {
@ -92,7 +148,7 @@ abstract class GherkinIntegrationTestRunner {
(world as FlutterWorld).setAppAdapter(WidgetTesterAppDriverAdapter(tester));
return _TestDependencies(
return TestDependencies(
world,
attachmentManager,
);
@ -103,7 +159,7 @@ abstract class GherkinIntegrationTestRunner {
String step,
Iterable<String> multiLineStrings,
dynamic table,
_TestDependencies dependencies,
TestDependencies dependencies,
) async {
final executable = _executableSteps.firstWhere(
(s) => s.expression.isMatch(step),
@ -152,7 +208,7 @@ abstract class GherkinIntegrationTestRunner {
}
@protected
void cleanupScenarioRun(_TestDependencies dependencies) {
void cleanupScenarioRun(TestDependencies dependencies) {
_safeInvokeFuture(
() async => await dependencies.attachmentManager.dispose());
_safeInvokeFuture(() async => await dependencies.world.dispose());
@ -234,7 +290,7 @@ abstract class GherkinIntegrationTestRunner {
Future<void> _onAfterStepRun(
String step,
StepResult result,
_TestDependencies dependencies,
TestDependencies dependencies,
) async {
await _hook.onAfterStep(
dependencies.world,

View File

@ -165,8 +165,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
resolved-ref: "59b9db42e917927ccb8d1265e6cb8fe93ddbb73a"
ref: "80c03137d883637b2526e16a945009d76c3cbd85"
resolved-ref: "80c03137d883637b2526e16a945009d76c3cbd85"
url: "https://github.com/jonsamwell/dart_gherkin.git"
source: git
version: "1.1.10"

View File

@ -27,7 +27,7 @@ dependencies:
gherkin:
git:
url: https://github.com/jonsamwell/dart_gherkin.git
ref: 59b9db42e917927ccb8d1265e6cb8fe93ddbb73a
ref: 80c03137d883637b2526e16a945009d76c3cbd85
# ref: code_gen_changes
dev_dependencies: