This commit is contained in:
2026-03-31 08:51:33 +08:00
commit e9f4844352
63 changed files with 8950 additions and 0 deletions

View 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
View 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');
});
}