This commit is contained in:
Developer
2026-07-06 15:20:14 +08:00
commit a6f13acb55
46 changed files with 1210 additions and 0 deletions
@@ -0,0 +1,26 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ch934x_serial/ch934x_serial_method_channel.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
MethodChannelCh934xSerial platform = MethodChannelCh934xSerial();
const MethodChannel channel = MethodChannel('ch934x_serial');
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');
});
}
+28
View File
@@ -0,0 +1,28 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:ch934x_serial/ch934x_serial.dart';
import 'package:ch934x_serial/ch934x_serial_platform_interface.dart';
import 'package:ch934x_serial/ch934x_serial_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockCh934xSerialPlatform
with MockPlatformInterfaceMixin
implements Ch934xSerialPlatform {
@override
Future<String?> getPlatformVersion() => Future.value('42');
}
void main() {
final Ch934xSerialPlatform initialPlatform = Ch934xSerialPlatform.instance;
test('$MethodChannelCh934xSerial is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelCh934xSerial>());
});
test('getPlatformVersion', () async {
Ch934xSerial ch934xSerialPlugin = Ch934xSerial();
MockCh934xSerialPlatform fakePlatform = MockCh934xSerialPlatform();
Ch934xSerialPlatform.instance = fakePlatform;
expect(await ch934xSerialPlugin.getPlatformVersion(), '42');
});
}