decouple flutter drive from flutter start
flutter start's method of finding devices to run the app on is not suitable for flutter drive. This commit also refactors several tool services to allow mocking in unit tests.
This commit is contained in:
@@ -7,9 +7,13 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/ios/simulators.dart';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
/// Return the test logger. This assumes that the current Logger is a BufferLogger.
|
||||
@@ -38,6 +42,15 @@ void testUsingContext(String description, dynamic testMethod(), {
|
||||
if (!overrides.containsKey(Doctor))
|
||||
testContext[Doctor] = new MockDoctor();
|
||||
|
||||
if (!overrides.containsKey(SimControl))
|
||||
testContext[SimControl] = new MockSimControl();
|
||||
|
||||
if (!overrides.containsKey(OperatingSystemUtils))
|
||||
testContext[OperatingSystemUtils] = new MockOperatingSystemUtils();
|
||||
|
||||
if (!overrides.containsKey(IOSSimulatorUtils))
|
||||
testContext[IOSSimulatorUtils] = new MockIOSSimulatorUtils();
|
||||
|
||||
if (Platform.isMacOS) {
|
||||
if (!overrides.containsKey(XCode))
|
||||
testContext[XCode] = new XCode();
|
||||
@@ -76,3 +89,13 @@ class MockDoctor extends Doctor {
|
||||
// True for testing.
|
||||
bool get canLaunchAnything => true;
|
||||
}
|
||||
|
||||
class MockSimControl extends Mock implements SimControl {
|
||||
MockSimControl() {
|
||||
when(this.getConnectedDevices()).thenReturn([]);
|
||||
}
|
||||
}
|
||||
|
||||
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
|
||||
|
||||
class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils {}
|
||||
|
||||
@@ -12,8 +12,6 @@ import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:flutter_tools/src/toolchain.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'context.dart';
|
||||
|
||||
class MockApplicationPackageStore extends ApplicationPackageStore {
|
||||
MockApplicationPackageStore() : super(
|
||||
android: new AndroidApk(localPath: '/mock/path/to/android/SkyShell.apk'),
|
||||
@@ -53,13 +51,10 @@ class MockDeviceStore extends DeviceStore {
|
||||
iOSSimulator: new MockIOSSimulator());
|
||||
}
|
||||
|
||||
void applyMocksToCommand(FlutterCommand command, { bool noDevices: false }) {
|
||||
void applyMocksToCommand(FlutterCommand command) {
|
||||
command
|
||||
..applicationPackages = new MockApplicationPackageStore()
|
||||
..toolchain = new MockToolchain()
|
||||
..devices = new MockDeviceStore()
|
||||
..projectRootValidator = () => true;
|
||||
|
||||
if (!noDevices)
|
||||
testDeviceManager.addDevice(command.devices.android);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user