widget_test.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This is a basic Flutter widget test.
  2. // To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter
  3. // provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to
  4. // find child widgets in the widget tree, read text, and verify that the values of widget properties
  5. // are correct.
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_test/flutter_test.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_sound_example/main.dart';
  10. void main() {
  11. final List<MethodCall> log = <MethodCall>[];
  12. MethodChannel channel = const MethodChannel('plugins.flutter_sound/flutter_sound');
  13. channel.setMockMethodCallHandler((MethodCall methodCall) async {
  14. log.add(methodCall);
  15. });
  16. test('Audio Recorder', () async {
  17. expect(log, equals(<MethodCall>[new MethodCall('startRecorder', "")]));
  18. });
  19. // Unregister the mock handler.
  20. channel.setMockMethodCallHandler(null);
  21. testWidgets('Render test', (WidgetTester tester) async {
  22. // Build our app and trigger a frame.
  23. await tester.pumpWidget(new MyApp());
  24. // Verify that platform version is retrieved.
  25. expect(
  26. find.byWidgetPredicate(
  27. (Widget widget) =>
  28. widget is Text && widget.data.startsWith('Flutter Sound'),
  29. ),
  30. findsOneWidget);
  31. });
  32. }