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
7912cbea
Unverified
Commit
7912cbea
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 cold test (#81550)
parent
50ace38c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
54 deletions
+68
-54
cold_test.dart
packages/flutter_tools/test/general.shard/cold_test.dart
+68
-54
No files found.
packages/flutter_tools/test/general.shard/cold_test.dart
View file @
7912cbea
...
...
@@ -16,7 +16,7 @@ import 'package:flutter_tools/src/run_cold.dart';
import
'package:flutter_tools/src/tracing.dart'
;
import
'package:flutter_tools/src/vmservice.dart'
;
import
'package:meta/meta.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'package:vm_service/vm_service.dart'
;
import
'../src/common.dart'
;
...
...
@@ -26,15 +26,13 @@ void main() {
testUsingContext
(
'Exits with code 2 when when HttpException is thrown '
'during VM service connection'
,
()
async
{
final
FakeResidentCompiler
residentCompiler
=
FakeResidentCompiler
();
final
MockDevice
mockDevice
=
MockDevice
();
when
(
mockDevice
.
supportsHotReload
).
thenReturn
(
true
);
when
(
mockDevice
.
supportsHotRestart
).
thenReturn
(
false
);
when
(
mockDevice
.
targetPlatform
).
thenAnswer
((
Invocation
_
)
async
=>
TargetPlatform
.
tester
);
when
(
mockDevice
.
sdkNameAndVersion
).
thenAnswer
((
Invocation
_
)
async
=>
'Android 10'
);
final
FakeDevice
device
=
FakeDevice
()
..
supportsHotReload
=
true
..
supportsHotRestart
=
false
;
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
TestFlutterDevice
(
device:
mockD
evice
,
device:
d
evice
,
generator:
residentCompiler
,
exception:
const
HttpException
(
'Connection closed before full header was received, '
'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'
),
...
...
@@ -51,29 +49,23 @@ void main() {
});
group
(
'cleanupAtFinish()'
,
()
{
MockFlutterDevice
mockFlutterDeviceFactory
(
Device
device
)
{
final
MockFlutterDevice
mockFlutterDevice
=
MockFlutterDevice
();
when
(
mockFlutterDevice
.
device
).
thenReturn
(
device
);
return
mockFlutterDevice
;
}
testUsingContext
(
'disposes each device'
,
()
async
{
final
MockDevice
mockDevice1
=
Mock
Device
();
final
MockDevice
mockDevice2
=
Mock
Device
();
final
MockFlutterDevice
mockFlutterDevice1
=
mockFlutterDeviceFactory
(
mockD
evice1
);
final
MockFlutterDevice
mockFlutterDevice2
=
mockFlutterDeviceFactory
(
mockD
evice2
);
final
FakeDevice
device1
=
Fake
Device
();
final
FakeDevice
device2
=
Fake
Device
();
final
FakeFlutterDevice
flutterDevice1
=
FakeFlutterDevice
(
d
evice1
);
final
FakeFlutterDevice
flutterDevice2
=
FakeFlutterDevice
(
d
evice2
);
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
mockFlutterDevice1
,
mockF
lutterDevice2
];
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
flutterDevice1
,
f
lutterDevice2
];
await
ColdRunner
(
devices
,
debuggingOptions:
DebuggingOptions
.
enabled
(
BuildInfo
.
debug
),
target:
'main.dart'
,
).
cleanupAtFinish
();
verify
(
mockDevice1
.
dispose
()
);
expect
(
mockFlutterDevice1
.
stopEchoingDeviceLogCount
,
1
);
verify
(
mockDevice2
.
dispose
()
);
expect
(
mockFlutterDevice2
.
stopEchoingDeviceLogCount
,
1
);
expect
(
flutterDevice1
.
stopEchoingDeviceLogCount
,
1
);
expect
(
flutterDevice2
.
stopEchoingDeviceLogCount
,
1
);
expect
(
device2
.
wasDisposed
,
true
);
expect
(
device1
.
wasDisposed
,
true
);
});
});
...
...
@@ -86,14 +78,10 @@ void main() {
});
testUsingContext
(
'calls runCold on attached device'
,
()
async
{
final
MockDevice
mockDevice
=
MockDevice
();
final
MockFlutterDevice
mockFlutterDevice
=
MockFlutterDevice
();
when
(
mockFlutterDevice
.
device
).
thenReturn
(
mockDevice
);
when
(
mockFlutterDevice
.
runCold
(
coldRunner:
anyNamed
(
'coldRunner'
),
route:
anyNamed
(
'route'
)
)).
thenAnswer
((
Invocation
invocation
)
=>
Future
<
int
>.
value
(
1
));
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
mockFlutterDevice
];
final
FakeDevice
device
=
FakeDevice
();
final
FakeFlutterDevice
flutterDevice
=
FakeFlutterDevice
(
device
)
..
runColdCode
=
1
;
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
flutterDevice
];
final
File
applicationBinary
=
MemoryFileSystem
.
test
().
file
(
'binary'
);
final
int
result
=
await
ColdRunner
(
devices
,
...
...
@@ -105,21 +93,12 @@ void main() {
);
expect
(
result
,
1
);
verify
(
mockFlutterDevice
.
runCold
(
coldRunner:
anyNamed
(
'coldRunner'
),
route:
anyNamed
(
'route'
),
));
});
testUsingContext
(
'with traceStartup, no env variable'
,
()
async
{
final
MockDevice
mockDevice
=
MockDevice
();
final
MockFlutterDevice
mockFlutterDevice
=
MockFlutterDevice
();
when
(
mockFlutterDevice
.
device
).
thenReturn
(
mockDevice
);
when
(
mockFlutterDevice
.
runCold
(
coldRunner:
anyNamed
(
'coldRunner'
),
route:
anyNamed
(
'route'
)
)).
thenAnswer
((
Invocation
invocation
)
=>
Future
<
int
>.
value
(
0
));
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
mockFlutterDevice
];
final
FakeDevice
device
=
FakeDevice
();
final
FakeFlutterDevice
flutterDevice
=
FakeFlutterDevice
(
device
);
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
flutterDevice
];
final
File
applicationBinary
=
MemoryFileSystem
.
test
().
file
(
'binary'
);
final
int
result
=
await
ColdRunner
(
devices
,
...
...
@@ -142,14 +121,9 @@ void main() {
testUsingContext
(
'with traceStartup, env variable'
,
()
async
{
fakePlatform
.
environment
[
kFlutterTestOutputsDirEnvName
]
=
'test_output_dir'
;
final
MockDevice
mockDevice
=
MockDevice
();
final
MockFlutterDevice
mockFlutterDevice
=
MockFlutterDevice
();
when
(
mockFlutterDevice
.
device
).
thenReturn
(
mockDevice
);
when
(
mockFlutterDevice
.
runCold
(
coldRunner:
anyNamed
(
'coldRunner'
),
route:
anyNamed
(
'route'
)
)).
thenAnswer
((
Invocation
invocation
)
=>
Future
<
int
>.
value
(
0
));
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
mockFlutterDevice
];
final
FakeDevice
device
=
FakeDevice
();
final
FakeFlutterDevice
flutterDevice
=
FakeFlutterDevice
(
device
);
final
List
<
FlutterDevice
>
devices
=
<
FlutterDevice
>[
flutterDevice
];
final
File
applicationBinary
=
MemoryFileSystem
.
test
().
file
(
'binary'
);
final
int
result
=
await
ColdRunner
(
devices
,
...
...
@@ -171,7 +145,15 @@ void main() {
});
}
class
MockFlutterDevice
extends
Mock
implements
FlutterDevice
{
class
FakeFlutterDevice
extends
Fake
implements
FlutterDevice
{
FakeFlutterDevice
(
this
.
device
);
@override
Stream
<
Uri
>
get
observatoryUris
=>
const
Stream
<
Uri
>.
empty
();
@override
final
Device
device
;
int
stopEchoingDeviceLogCount
=
0
;
@override
...
...
@@ -181,10 +163,42 @@ class MockFlutterDevice extends Mock implements FlutterDevice {
@override
FlutterVmService
get
vmService
=>
FakeFlutterVmService
();
int
runColdCode
=
0
;
@override
Future
<
int
>
runCold
({
ColdRunner
coldRunner
,
String
route
})
async
{
return
runColdCode
;
}
@override
Future
<
void
>
initLogReader
()
async
{
}
}
class
MockDevice
extends
Mock
implements
Device
{
MockDevice
()
{
when
(
isSupported
()).
thenReturn
(
true
);
class
FakeDevice
extends
Fake
implements
Device
{
@override
bool
isSupported
()
=>
true
;
@override
bool
supportsHotReload
;
@override
bool
supportsHotRestart
;
@override
Future
<
String
>
get
sdkNameAndVersion
async
=>
'Android 10'
;
@override
String
get
name
=>
'test'
;
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
tester
;
bool
wasDisposed
=
false
;
@override
Future
<
void
>
dispose
()
async
{
wasDisposed
=
true
;
}
}
...
...
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