diff --git a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart index 43cb66b017..75c2424a3d 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart @@ -25,7 +25,6 @@ import '../../src/mocks.dart'; void main() { group('drive', () { DriveCommand command; - Device mockDevice; Device mockUnsupportedDevice; MemoryFileSystem fs; Directory tempDir; @@ -249,7 +248,7 @@ void main() { group('findTargetDevice', () { testUsingContext('uses specified device', () async { testDeviceManager.specifiedDeviceId = '123'; - mockDevice = MockDevice(); + final Device mockDevice = MockDevice(); testDeviceManager.addDevice(mockDevice); when(mockDevice.name).thenReturn('specified-device'); when(mockDevice.id).thenReturn('123'); @@ -274,7 +273,7 @@ void main() { }); testUsingContext('uses existing Android device', () async { - mockDevice = MockAndroidDevice(); + final Device mockDevice = MockAndroidDevice(); when(mockDevice.name).thenReturn('mock-android-device'); testDeviceManager.addDevice(mockDevice); @@ -287,7 +286,7 @@ void main() { }); testUsingContext('skips unsupported device', () async { - mockDevice = MockAndroidDevice(); + final Device mockDevice = MockAndroidDevice(); mockUnsupportedDevice = MockDevice(); when(mockUnsupportedDevice.isSupportedForProject(any)) .thenReturn(false); @@ -333,6 +332,7 @@ void main() { Platform macOsPlatform() => FakePlatform(operatingSystem: 'macos'); testUsingContext('uses existing simulator', () async { + final Device mockDevice = MockDevice(); testDeviceManager.addDevice(mockDevice); when(mockDevice.name).thenReturn('mock-simulator'); when(mockDevice.isLocalEmulator) @@ -354,8 +354,8 @@ void main() { restoreAppStarter(); }); - Future appStarterSetup() async { - mockDevice = MockDevice(); + Future appStarterSetup() async { + final Device mockDevice = MockDevice(); testDeviceManager.addDevice(mockDevice); final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader(); @@ -388,10 +388,11 @@ void main() { final MemoryFileSystem memFs = fs; await memFs.file(testApp).writeAsString('main() {}'); await memFs.file(testFile).writeAsString('main() {}'); + return mockDevice; } testUsingContext('does not use pre-built app if no build arg provided', () async { - await appStarterSetup(); + final Device mockDevice = await appStarterSetup(); final List args = [ 'drive', @@ -418,7 +419,7 @@ void main() { }); testUsingContext('does not use pre-built app if --build arg provided', () async { - await appStarterSetup(); + final Device mockDevice = await appStarterSetup(); final List args = [ 'drive', @@ -446,7 +447,7 @@ void main() { }); testUsingContext('uses prebuilt app if --no-build arg provided', () async { - await appStarterSetup(); + final Device mockDevice = await appStarterSetup(); final List args = [ 'drive', @@ -483,8 +484,8 @@ void main() { restoreAppStarter(); }); - Future appStarterSetup() async { - mockDevice = MockDevice(); + Future appStarterSetup() async { + final Device mockDevice = MockDevice(); testDeviceManager.addDevice(mockDevice); final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader(); @@ -521,6 +522,7 @@ void main() { final MemoryFileSystem memFs = fs; await memFs.file(testApp).writeAsString('main() {}'); await memFs.file(testFile).writeAsString('main() {}'); + return mockDevice; } void _testOptionThatDefaultsToFalse( @@ -529,7 +531,7 @@ void main() { bool optionValue(), ) { testUsingContext('$optionName ${setToTrue ? 'works' : 'defaults to false'}', () async { - await appStarterSetup(); + final Device mockDevice = await appStarterSetup(); final List args = [ 'drive', diff --git a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart index 473b1155a8..5517c430a9 100644 --- a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart @@ -35,6 +35,7 @@ void main() { setUpAll(() { Cache.disableLocking(); + Cache.flutterRoot = FlutterCommandRunner.defaultFlutterRoot; }); setUp(() {