Unverified Commit e868a833 authored by Jia Hao's avatar Jia Hao Committed by GitHub

Remove the warning about the Integration Test plugin (#79520)

parent 42c5f71c
<<skip until matching line>>
[0-9]+:[0-9]+ [+]1: All tests passed! [0-9]+:[0-9]+ [+]1: All tests passed!
...@@ -401,6 +401,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ...@@ -401,6 +401,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
if (_isIntegrationTest) { if (_isIntegrationTest) {
integrationTestDevice = await findTargetDevice(); integrationTestDevice = await findTargetDevice();
// Disable reporting of test results to native test frameworks. This isn't
// needed as the Flutter Tool will be responsible for reporting results.
buildInfo.dartDefines.add('INTEGRATION_TEST_SHOULD_REPORT_RESULTS_TO_NATIVE=false');
if (integrationTestDevice == null) { if (integrationTestDevice == null) {
throwToolExit( throwToolExit(
'No devices are connected. ' 'No devices are connected. '
......
...@@ -582,6 +582,30 @@ dev_dependencies: ...@@ -582,6 +582,30 @@ dev_dependencies:
FakeDevice('ephemeral', 'ephemeral', ephemeral: true, isSupported: true, type: PlatformType.web), FakeDevice('ephemeral', 'ephemeral', ephemeral: true, isSupported: true, type: PlatformType.web),
]), ]),
}); });
testUsingContext('Integration tests set the correct dart-defines', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
final TestCommand testCommand = TestCommand(testRunner: testRunner);
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
await commandRunner.run(const <String>[
'test',
'--no-pub',
'integration_test',
]);
expect(
testRunner.lastDebuggingOptionsValue.buildInfo.dartDefines,
contains('INTEGRATION_TEST_SHOULD_REPORT_RESULTS_TO_NATIVE=false'),
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
DeviceManager: () => _FakeDeviceManager(<Device>[
FakeDevice('ephemeral', 'ephemeral', ephemeral: true, isSupported: true, type: PlatformType.android),
]),
});
} }
class FakeFlutterTestRunner implements FlutterTestRunner { class FakeFlutterTestRunner implements FlutterTestRunner {
...@@ -589,6 +613,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner { ...@@ -589,6 +613,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
int exitCode; int exitCode;
bool lastEnableObservatoryValue; bool lastEnableObservatoryValue;
DebuggingOptions lastDebuggingOptionsValue;
@override @override
Future<int> runTests( Future<int> runTests(
...@@ -626,6 +651,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner { ...@@ -626,6 +651,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
String integrationTestUserIdentifier, String integrationTestUserIdentifier,
}) async { }) async {
lastEnableObservatoryValue = enableObservatory; lastEnableObservatoryValue = enableObservatory;
lastDebuggingOptionsValue = debuggingOptions;
return exitCode; return exitCode;
} }
} }
......
...@@ -20,24 +20,37 @@ import 'common.dart'; ...@@ -20,24 +20,37 @@ import 'common.dart';
const String _success = 'success'; const String _success = 'success';
/// Whether results should be reported to the native side over the method
/// channel.
///
/// This is enabled by default for use by native test frameworks like Android
/// instrumentation or XCTest. When running with the Flutter Tool through
/// `flutter test integration_test` though, it will be disabled as the Flutter
/// tool will be responsible for collection of test results.
const bool _shouldReportResultsToNative = bool.fromEnvironment(
'INTEGRATION_TEST_SHOULD_REPORT_RESULTS_TO_NATIVE',
defaultValue: true,
);
/// A subclass of [LiveTestWidgetsFlutterBinding] that reports tests results /// A subclass of [LiveTestWidgetsFlutterBinding] that reports tests results
/// on a channel to adapt them to native instrumentation test format. /// on a channel to adapt them to native instrumentation test format.
class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding implements IntegrationTestResults { class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding implements IntegrationTestResults {
/// Sets up a listener to report that the tests are finished when everything is /// Sets up a listener to report that the tests are finished when everything is
/// torn down. /// torn down.
IntegrationTestWidgetsFlutterBinding() { IntegrationTestWidgetsFlutterBinding() {
// TODO(jackson): Report test results as they arrive
tearDownAll(() async { tearDownAll(() async {
if (!_allTestsPassed.isCompleted) {
_allTestsPassed.complete(true);
}
callbackManager.cleanup();
// TODO(jiahaog): Print the message directing users to run with
// `flutter test` when Web is supported.
if (!_shouldReportResultsToNative || kIsWeb) {
return;
}
try { try {
// For web integration tests we are not using the
// `plugins.flutter.io/integration_test`. Mark the tests as complete
// before invoking the channel.
if (kIsWeb) {
if (!_allTestsPassed.isCompleted) {
_allTestsPassed.complete(true);
}
}
callbackManager.cleanup();
await _channel.invokeMethod<void>( await _channel.invokeMethod<void>(
'allTestsFinished', 'allTestsFinished',
<String, dynamic>{ <String, dynamic>{
...@@ -50,15 +63,22 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding ...@@ -50,15 +63,22 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding
}, },
); );
} on MissingPluginException { } on MissingPluginException {
print('Warning: integration_test test plugin was not detected.'); print(r'''
} Warning: integration_test plugin was not detected.
if (!_allTestsPassed.isCompleted) {
_allTestsPassed.complete(true); If you're running the tests with `flutter drive`, please make sure your tests
are in the `integration_test/` directory of your package and use
`flutter test $path_to_test` to run it instead.
If you're running the tests with Android instrumentation or XCTest, this means
that you are not capturing test results properly! See the following link for
how to set up the integration_test plugin:
https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
''');
} }
}); });
// TODO(jackson): Report the results individually instead of all at once
// See https://github.com/flutter/flutter/issues/38985
final TestExceptionReporter oldTestExceptionReporter = reportTestException; final TestExceptionReporter oldTestExceptionReporter = reportTestException;
reportTestException = reportTestException =
(FlutterErrorDetails details, String testDescription) { (FlutterErrorDetails details, String testDescription) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment