mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add some emulator tests
This commit is contained in:
parent
2bdb3bbe0e
commit
486e9534bf
@ -119,7 +119,7 @@ abstract class Emulator {
|
||||
|
||||
final String id;
|
||||
|
||||
String get name;
|
||||
String get name => id;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
|
57
packages/flutter_tools/test/emulator_test.dart
Normal file
57
packages/flutter_tools/test/emulator_test.dart
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/emulator.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'src/context.dart';
|
||||
|
||||
void main() {
|
||||
group('EmulatorManager', () {
|
||||
testUsingContext('getEmulators', () async {
|
||||
// Test that EmulatorManager.getEmulators() doesn't throw.
|
||||
final EmulatorManager emulatorManager = new EmulatorManager();
|
||||
final List<Emulator> emulators = await emulatorManager.getAllAvailableEmulators().toList();
|
||||
expect(emulators, isList);
|
||||
});
|
||||
|
||||
testUsingContext('getEmulatorsById', () async {
|
||||
final _MockEmulator emulator1 = new _MockEmulator('Nexus_5');
|
||||
final _MockEmulator emulator2 = new _MockEmulator('Nexus_5X_API_27_x86');
|
||||
final _MockEmulator emulator3 = new _MockEmulator('iOS Simulator');
|
||||
final List<Emulator> emulators = <Emulator>[emulator1, emulator2, emulator3];
|
||||
final EmulatorManager emulatorManager = new TestEmulatorManager(emulators);
|
||||
|
||||
Future<Null> expectEmulator(String id, List<Emulator> expected) async {
|
||||
expect(await emulatorManager.getEmulatorsById(id).toList(), expected);
|
||||
}
|
||||
expectEmulator('Nexus_5', <Emulator>[emulator1]);
|
||||
expectEmulator('Nexus_5X', <Emulator>[emulator2]);
|
||||
expectEmulator('Nexus_5X_API_27_x86', <Emulator>[emulator2]);
|
||||
expectEmulator('Nexus', <Emulator>[emulator1, emulator2]);
|
||||
expectEmulator('iOS Simulator', <Emulator>[emulator3]);
|
||||
expectEmulator('ios', <Emulator>[emulator3]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class TestEmulatorManager extends EmulatorManager {
|
||||
final List<Emulator> allEmulators;
|
||||
|
||||
TestEmulatorManager(this.allEmulators);
|
||||
|
||||
@override
|
||||
Stream<Emulator> getAllAvailableEmulators() {
|
||||
return new Stream<Emulator>.fromIterable(allEmulators);
|
||||
}
|
||||
}
|
||||
|
||||
class _MockEmulator extends Emulator {
|
||||
_MockEmulator(String id) : super(id);
|
||||
|
||||
@override
|
||||
void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
Loading…
Reference in New Issue
Block a user