init
This commit is contained in:
27
test/zhiwen_method_channel_test.dart
Normal file
27
test/zhiwen_method_channel_test.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:zhiwen/zhiwen_method_channel.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
MethodChannelZhiwen platform = MethodChannelZhiwen();
|
||||
const MethodChannel channel = MethodChannel('zhiwen');
|
||||
|
||||
setUp(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
(MethodCall methodCall) async {
|
||||
return '42';
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test('getPlatformVersion', () async {
|
||||
expect(await platform.getPlatformVersion(), '42');
|
||||
});
|
||||
}
|
||||
29
test/zhiwen_test.dart
Normal file
29
test/zhiwen_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:zhiwen/zhiwen.dart';
|
||||
import 'package:zhiwen/zhiwen_platform_interface.dart';
|
||||
import 'package:zhiwen/zhiwen_method_channel.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
class MockZhiwenPlatform
|
||||
with MockPlatformInterfaceMixin
|
||||
implements ZhiwenPlatform {
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformVersion() => Future.value('42');
|
||||
}
|
||||
|
||||
void main() {
|
||||
final ZhiwenPlatform initialPlatform = ZhiwenPlatform.instance;
|
||||
|
||||
test('$MethodChannelZhiwen is the default instance', () {
|
||||
expect(initialPlatform, isInstanceOf<MethodChannelZhiwen>());
|
||||
});
|
||||
|
||||
test('getPlatformVersion', () async {
|
||||
Zhiwen zhiwenPlugin = Zhiwen();
|
||||
MockZhiwenPlatform fakePlatform = MockZhiwenPlatform();
|
||||
ZhiwenPlatform.instance = fakePlatform;
|
||||
|
||||
expect(await zhiwenPlugin.getPlatformVersion(), '42');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user