Skip to content

Run flutter tests through mini test engine when run directly (flutter run -t test_file) - #24930

Merged
jonahwilliams merged 13 commits into
flutter:masterfrom
jonahwilliams:fix_tests
Dec 12, 2018
Merged

jonahwilliams merged 13 commits into
flutter:masterfrom
jonahwilliams:fix_tests

Conversation

@jonahwilliams

@jonahwilliams jonahwilliams commented Dec 3, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #24650

If Declarer is not defined, we need to set up our own mini-engine to execute flutter tests and log messages. Instead of adding a dep on test_core, we duplicate a subset of the functionality needed for flutter run test. To intercept all of the calls, we hide test, group, setUp, setUpAll, tearDown, tearDownAll and re-export the same methods.

This code does not run when tests are executed via flutter test since the declarer is already defined.

This also adds an integration test that confirms that the output of flutter run -t works as expected.

@zoechi zoechi added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Dec 4, 2018
@jonahwilliams jonahwilliams changed the title [WIP] Check if declarer is defined before invoking test methods Run flutter tests through mini test engine when run directly (flutter run -t test_file) Dec 11, 2018
Comment thread dev/devicelab/bin/tasks/flutter_run_test.dart Outdated
@yjbanov

yjbanov commented Dec 11, 2018

Copy link
Copy Markdown
Contributor

Is there a reason why this needs to run in the devicelab? It does not seem to need any devices, so could run in Cirrus? LGTM otherwise.

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

This specifically verifies that flutter run -t test_file works, running a test via flutter test will go through the old paths since the declarer will be defined.

@yjbanov

yjbanov commented Dec 11, 2018

Copy link
Copy Markdown
Contributor

lgtm

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

cc @Hixie

Comment thread dev/devicelab/bin/tasks/flutter_run_test.dart Outdated
import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/message.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/invoker.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/state.dart'; // ignore: implementation_imports

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this is going to cost us a lot in technical debt...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a flaw in the test_api package. How are we supposed to do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These APIs are stable but haven't been formally made public yet. I've opened dart-lang/test#962 to track, but most of these could be moved to lib.

Comment thread packages/flutter_test/lib/src/test_compat.dart Outdated
Comment thread packages/flutter_test/lib/src/widget_tester.dart
@Hixie

Hixie commented Dec 12, 2018

Copy link
Copy Markdown
Contributor

As we keep reimplementing more and more of the test package, I see less and less reason to bother with it at all...

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

Fundamentally, test_api is a package to let you build your own test framework - but importantly it does so in a way that lets us be compatible with existing tests, mockito, matcher, et cetera.

@jonahwilliams
jonahwilliams merged commit f30029b into flutter:master Dec 12, 2018
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter run test/widget_test.dart no longer works

5 participants