Commit ed037a8a authored by yangwu.jia's avatar yangwu.jia

Test and travis tool

parent abb58ad6
os:
- linux
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++6
# - fonts-droid
before_script:
- git clone https://github.com/flutter/flutter.git -b v1.9.1-hotfixes --depth 1
- ./flutter/bin/flutter doctor
script:
- ./flutter/bin/flutter test --coverage --coverage-path=lcov.info
after_success:
- bash <(curl -s https://codecov.io/bash)
cache:
directories:
- $HOME/.pub-cache
...@@ -12,6 +12,11 @@ dependencies: ...@@ -12,6 +12,11 @@ dependencies:
sdk: flutter sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec # following page: https://www.dartlang.org/tools/pub/pubspec
......
import 'package:flutter_test/flutter_test.dart';
import 'package:boost_test/unit/boost_channel_test.dart' as boost_channel;
import 'package:boost_test/unit/boost_container_test.dart' as boost_container;
import 'package:boost_test/unit/boost_page_route_test.dart' as boost_page_route;
import 'package:boost_test/unit/container_coordinator_test.dart'
as container_coordinator;
import 'package:boost_test/unit/container_manager_test.dart'
as container_manager;
import 'package:boost_test/unit/flutter_boost_test.dart' as flutter_boost;
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('all_test', () {
boost_channel.main();
boost_container.main();
boost_page_route.main();
container_coordinator.main();
container_manager.main();
flutter_boost.main();
});
}
import 'package:flutter_boost/channel/boost_channel.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const MethodChannel channel = MethodChannel('flutter_boost');
final List<MethodCall> log = <MethodCall>[];
dynamic response;
channel.setMockMethodCallHandler((MethodCall methodCall) async {
print(methodCall);
log.add(methodCall);
return response;
});
tearDown(() {
log.clear();
});
group('boost_channel', () {
response = null;
test('sendEvent successfully', () async {
Map msg1 = Map();
BoostChannel().sendEvent("name", msg1);
Map msg = Map();
msg["name"] = "name";
msg["arguments"] = msg1;
expect(
log,
<Matcher>[isMethodCall('__event__', arguments: msg)],
);
});
test('invokeMethod successfully', () async {
Map msg = {};
msg["test"] = "test";
BoostChannel().invokeMethod("__event__1", msg);
// expect(e, isException);
expect(
log,
<Matcher>[isMethodCall('__event__1', arguments: msg)],
);
});
test('invokeListMethod successfully', () async {
Map msg = {};
msg["test"] = "test";
var bb = await BoostChannel().invokeListMethod("__event__1", msg);
expect(
log,
<Matcher>[isMethodCall('__event__1', arguments: msg)],
);
});
test('invokeMapMethod successfully', () async {
Map msg = {};
msg["test"] = "test";
BoostChannel().invokeMapMethod("__event__1", msg);
expect(
log,
<Matcher>[isMethodCall('__event__1', arguments: msg)],
);
});
test('invokeMapMethod successfully', () async {
Map msg = {};
msg["test"] = "test";
BoostChannel().invokeMapMethod("__event__1", msg);
expect(
log,
<Matcher>[isMethodCall('__event__1', arguments: msg)],
);
});
test('addEventListener successfully', () async {
Function test = BoostChannel().addEventListener(
"addEventListener", (String name, Map arguments) async => "test");
print("xxx" + test.toString());
expect(
test.toString(),
"Closure: () => Null",
);
});
test('addMethodHandler successfully', () async {
Function test = BoostChannel().addMethodHandler((
MethodCall call) async => "test");
expect(
test.toString(),
"Closure: () => Null",
);
});
});
}
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_boost/container/boost_container.dart';
import 'package:flutter_test/flutter_test.dart';
class FirstWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/second');
},
child: Container(
color: const Color(0xFFFFFF00),
child: const Text('X'),
),
);
}
}
class SecondWidget extends StatefulWidget {
@override
SecondWidgetState createState() => SecondWidgetState();
}
class SecondWidgetState extends State<SecondWidget> {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
color: const Color(0xFFFF00FF),
child: const Text('Y'),
),
);
}
}
typedef ExceptionCallback = void Function(dynamic exception);
class ThirdWidget extends StatelessWidget {
const ThirdWidget({ this.targetKey, this.onException });
final Key targetKey;
final ExceptionCallback onException;
@override
Widget build(BuildContext context) {
return GestureDetector(
key: targetKey,
onTap: () {
try {
Navigator.of(context);
} catch (e) {
onException(e);
}
},
behavior: HitTestBehavior.opaque,
);
}
}
class OnTapPage extends StatelessWidget {
const OnTapPage({ Key key, this.id, this.onTap }) : super(key: key);
final String id;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page $id')),
body: GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: Container(
child: Center(
child: Text(id, style: Theme.of(context).textTheme.display2),
),
),
),
);
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Can navigator navigate to and from a stateful widget', (
WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), // X
'/second': (BuildContext context) => SecondWidget(), // Y
};
await tester.pumpWidget(MaterialApp(routes: routes));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y', skipOffstage: false), findsNothing);
await tester.tap(find.text('X'));
await tester.pump();
expect(find.text('X'), findsOneWidget);
expect(find.text('Y', skipOffstage: false), isOffstage);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.pump(const Duration(seconds: 1));
expect(find.text('X'), findsNothing);
expect(find.text('X', skipOffstage: false), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.tap(find.text('Y'));
expect(find.text('X'), findsNothing);
expect(find.text('Y'), findsOneWidget);
await tester.pump();
await tester.pump();
expect(find.text('X'), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y'), findsOneWidget);
await tester.pump(const Duration(seconds: 1));
expect(find.text('X'), findsOneWidget);
expect(find.text('Y', skipOffstage: false), findsNothing);
});
//
testWidgets('Navigator.of fails gracefully when not found in context', (
WidgetTester tester) async {
const Key targetKey = Key('foo');
dynamic exception;
final Widget widget = ThirdWidget(
targetKey: targetKey,
onException: (dynamic e) {
exception = e;
},
);
await tester.pumpWidget(widget);
await tester.tap(find.byKey(targetKey));
expect(exception, isInstanceOf<FlutterError>());
expect('$exception',
startsWith('Navigator operation requested with a context'));
});
//
testWidgets('Navigator.of rootNavigator finds root Navigator', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Material(
child: Column(
children: <Widget>[
const SizedBox(
height: 300.0,
child: Text('Root page'),
),
SizedBox(
height: 300.0,
child: BoostContainer(
onGenerateRoute: (RouteSettings settings) {
if (settings.isInitialRoute) {
return MaterialPageRoute<void>(
builder: (BuildContext context) {
return RaisedButton(
child: const Text('Next'),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return RaisedButton(
child: const Text('Inner page'),
onPressed: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return const Text('Dialog');
}
),
);
},
);
}
),
);
},
);
},
);
}
return null;
},
),
),
],
),
),
));
await tester.tap(find.text('Next'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
// Both elements are on screen.
expect(tester.getTopLeft(find.text('Root page')).dy, 0.0);
expect(tester.getTopLeft(find.text('Inner page')).dy, greaterThan(300.0));
await tester.tap(find.text('Inner page'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
// Dialog is pushed to the whole page and is at the top of the screen, not
// inside the inner page.
expect(tester.getTopLeft(find.text('Dialog')).dy, 0.0);
});
}
\ No newline at end of file
import 'package:flutter_boost/container/boost_page_route.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('boost_page_route', () {
});
}
\ No newline at end of file
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('container_coordinator', () {
});
}
\ No newline at end of file
import 'package:flutter_boost/container/container_manager.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('container_manager', () {
});
}
\ No newline at end of file
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('boost_container', () {
});
}
\ No newline at end of file
name: boost_test
description: A new Flutter package.
version: 0.0.1
author:
homepage:
environment:
sdk: '>=2.2.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
test: ^1.5.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
e2e: ^0.2.1
mockito: 4.1.1
flutter_boost:
path: ../
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment