Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d4e48a15
Unverified
Commit
d4e48a15
authored
May 01, 2021
by
Jonah Williams
Committed by
GitHub
May 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from android emulator tests (#81548)
parent
3a0abac7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
62 deletions
+65
-62
android_emulator.dart
packages/flutter_tools/lib/src/android/android_emulator.dart
+2
-2
android_emulator_test.dart
...ols/test/general.shard/android/android_emulator_test.dart
+21
-37
emulator_test.dart
packages/flutter_tools/test/general.shard/emulator_test.dart
+42
-23
No files found.
packages/flutter_tools/lib/src/android/android_emulator.dart
View file @
d4e48a15
...
...
@@ -149,7 +149,7 @@ class AndroidEmulator extends Emulator {
String
_prop
(
String
name
)
=>
_properties
!=
null
?
_properties
[
name
]
:
null
;
@override
Future
<
void
>
launch
()
async
{
Future
<
void
>
launch
(
{
@visibleForTesting
Duration
startupDuration
}
)
async
{
final
Process
process
=
await
_processUtils
.
start
(
<
String
>[
_androidSdk
.
emulatorPath
,
'-avd'
,
id
],
);
...
...
@@ -200,7 +200,7 @@ class AndroidEmulator extends Emulator {
}));
// Wait a few seconds for the emulator to start.
await
Future
<
void
>.
delayed
(
const
Duration
(
seconds:
3
));
await
Future
<
void
>.
delayed
(
startupDuration
??
const
Duration
(
seconds:
3
));
earlyFailure
=
false
;
return
;
}
...
...
packages/flutter_tools/test/general.shard/android/android_emulator_test.dart
View file @
d4e48a15
...
...
@@ -6,16 +6,14 @@
import
'dart:async'
;
import
'package:fake_async/fake_async.dart'
;
import
'package:flutter_tools/src/android/android_emulator.dart'
;
import
'package:flutter_tools/src/
base/common
.dart'
;
import
'package:flutter_tools/src/
android/android_sdk
.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/fake_process_manager.dart'
;
import
'../../src/mocks.dart'
show
MockAndroidSdk
;
const
String
emulatorID
=
'i1234'
;
const
String
errorText
=
'[Android emulator test error]'
;
...
...
@@ -32,7 +30,7 @@ void main() {
emulatorID
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
);
expect
(
emulator
.
id
,
emulatorID
);
expect
(
emulator
.
hasConfig
,
false
);
...
...
@@ -45,7 +43,7 @@ void main() {
properties:
const
<
String
,
String
>{
'name'
:
'test'
},
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
);
expect
(
emulator
.
id
,
emulatorID
);
...
...
@@ -65,7 +63,7 @@ void main() {
properties:
properties
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
);
expect
(
emulator
.
id
,
emulatorID
);
...
...
@@ -86,7 +84,7 @@ void main() {
properties:
properties
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
);
expect
(
emulator
.
name
,
displayName
);
...
...
@@ -104,7 +102,7 @@ void main() {
properties:
properties
,
logger:
BufferLogger
.
test
(),
processManager:
FakeProcessManager
.
any
(),
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
);
expect
(
emulator
.
name
,
'This is my ID'
);
...
...
@@ -127,11 +125,11 @@ void main() {
});
group
(
'Android emulator launch '
,
()
{
Mock
AndroidSdk
mockSdk
;
Fake
AndroidSdk
mockSdk
;
setUp
(()
{
mockSdk
=
Mock
AndroidSdk
();
when
(
mockSdk
.
emulatorPath
).
thenReturn
(
'emulator'
)
;
mockSdk
=
Fake
AndroidSdk
();
mockSdk
.
emulatorPath
=
'emulator'
;
});
testWithoutContext
(
'succeeds'
,
()
async
{
...
...
@@ -143,13 +141,7 @@ void main() {
logger:
BufferLogger
.
test
(),
);
final
Completer
<
void
>
completer
=
Completer
<
void
>();
FakeAsync
().
run
((
FakeAsync
time
)
{
unawaited
(
emulator
.
launch
().
whenComplete
(
completer
.
complete
));
time
.
elapse
(
const
Duration
(
seconds:
5
));
time
.
flushMicrotasks
();
});
await
completer
.
future
;
await
emulator
.
launch
(
startupDuration:
Duration
.
zero
);
});
testWithoutContext
(
'prints error on failure'
,
()
async
{
...
...
@@ -161,20 +153,13 @@ void main() {
exitCode:
1
,
stderr:
errorText
,
stdout:
'dummy text'
,
duration:
Duration
(
seconds:
1
),
),
]),
androidSdk:
mockSdk
,
logger:
logger
,
);
final
Completer
<
void
>
completer
=
Completer
<
void
>();
FakeAsync
().
run
((
FakeAsync
time
)
{
unawaited
(
emulator
.
launch
().
whenComplete
(
completer
.
complete
));
time
.
elapse
(
const
Duration
(
seconds:
5
));
time
.
flushMicrotasks
();
});
await
completer
.
future
;
await
emulator
.
launch
(
startupDuration:
Duration
.
zero
);
expect
(
logger
.
errorText
,
contains
(
errorText
));
});
...
...
@@ -183,26 +168,25 @@ void main() {
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
AndroidEmulator
emulator
=
AndroidEmulator
(
emulatorID
,
processManager:
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
FakeCommand
(
command:
kEmulatorLaunchCommand
,
exitCode:
1
,
stderr:
''
,
stdout:
'dummy text'
,
duration:
Duration
(
seconds:
4
),
completer:
Completer
<
void
>(
),
),
]),
androidSdk:
mockSdk
,
logger:
logger
,
);
final
Completer
<
void
>
completer
=
Completer
<
void
>();
await
FakeAsync
().
run
((
FakeAsync
time
)
async
{
unawaited
(
emulator
.
launch
().
whenComplete
(
completer
.
complete
));
time
.
elapse
(
const
Duration
(
seconds:
5
));
time
.
flushMicrotasks
();
});
await
completer
.
future
;
await
emulator
.
launch
(
startupDuration:
Duration
.
zero
);
expect
(
logger
.
errorText
,
isEmpty
);
}
,
skip:
true
);
// TODO(jonahwilliams): clean up with https://github.com/flutter/flutter/issues/60675
}
);
});
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
@override
String
emulatorPath
;
}
packages/flutter_tools/test/general.shard/emulator_test.dart
View file @
d4e48a15
...
...
@@ -6,18 +6,18 @@
import
'package:file/file.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/android/android_sdk.dart'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/emulator.dart'
;
import
'package:flutter_tools/src/ios/ios_emulators.dart'
;
import
'package:flutter_tools/src/macos/xcode.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/fakes.dart'
;
import
'../src/mocks.dart'
;
const
FakeEmulator
emulator1
=
FakeEmulator
(
'Nexus_5'
,
'Nexus 5'
,
'Google'
);
const
FakeEmulator
emulator2
=
FakeEmulator
(
'Nexus_5X_API_27_x86'
,
'Nexus 5X'
,
'Google'
);
...
...
@@ -29,7 +29,7 @@ const List<Emulator> emulators = <Emulator>[
];
// We have to send a command that fails in order to get the list of valid
// system images paths. This is an example of the output to use in the
mock
.
// system images paths. This is an example of the output to use in the
fake
.
const
String
fakeCreateFailureOutput
=
'Error: Package path (-k) not specified. Valid system image paths are:
\n
'
'system-images;android-27;google_apis;x86
\n
'
...
...
@@ -45,20 +45,20 @@ const FakeCommand kListEmulatorsCommand = FakeCommand(
void
main
(
)
{
FakeProcessManager
fakeProcessManager
;
MockAndroidSdk
mockS
dk
;
FakeAndroidSdk
s
dk
;
FileSystem
fileSystem
;
Xcode
xcode
;
setUp
(()
{
fileSystem
=
MemoryFileSystem
.
test
();
fakeProcessManager
=
FakeProcessManager
.
empty
();
mockSdk
=
Mock
AndroidSdk
();
sdk
=
Fake
AndroidSdk
();
xcode
=
Xcode
.
test
(
processManager:
fakeProcessManager
,
fileSystem:
fileSystem
);
when
(
mockSdk
.
avdManagerPath
).
thenReturn
(
'avdmanager'
);
when
(
mockSdk
.
getAvdManagerPath
()).
thenReturn
(
'avdmanager'
);
when
(
mockSdk
.
emulatorPath
).
thenReturn
(
'emulator'
);
when
(
mockSdk
.
adbPath
).
thenReturn
(
'adb'
)
;
sdk
..
avdManagerPath
=
'avdmanager'
..
emulatorPath
=
'emulator'
..
adbPath
=
'adb'
;
});
group
(
'EmulatorManager'
,
()
{
...
...
@@ -74,9 +74,9 @@ void main() {
stdout:
'existing-avd-1'
,
),
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -121,8 +121,7 @@ void main() {
});
testUsingContext
(
'create emulator with a missing avdmanager does not crash.'
,
()
async
{
when
(
mockSdk
.
avdManagerPath
).
thenReturn
(
null
);
when
(
mockSdk
.
getAvdManagerPath
()).
thenReturn
(
null
);
sdk
.
avdManagerPath
=
null
;
final
EmulatorManager
emulatorManager
=
EmulatorManager
(
fileSystem:
MemoryFileSystem
.
test
(),
logger:
BufferLogger
.
test
(),
...
...
@@ -132,9 +131,9 @@ void main() {
stdout:
'existing-avd-1'
,
),
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -174,9 +173,9 @@ void main() {
],
)
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -211,9 +210,9 @@ void main() {
],
)
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -250,9 +249,9 @@ void main() {
'Use --force if you want to replace it.'
)
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -292,9 +291,9 @@ void main() {
],
)
]),
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
androidWorkflow:
AndroidWorkflow
(
androidSdk:
mockS
dk
,
androidSdk:
s
dk
,
featureFlags:
TestFeatureFlags
(),
operatingSystemUtils:
FakeOperatingSystemUtils
(),
),
...
...
@@ -372,3 +371,23 @@ class FakeEmulator extends Emulator {
throw
UnimplementedError
(
'Not implemented in Mock'
);
}
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
@override
String
avdManagerPath
;
@override
String
emulatorPath
;
@override
String
adbPath
;
@override
String
getAvdManagerPath
()
=>
avdManagerPath
;
@override
String
getAvdPath
()
=>
'avd'
;
@override
Map
<
String
,
String
>
get
sdkManagerEnv
=>
<
String
,
String
>{};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment