From f9100e2125582360fe63324ebf6fdc322182618e Mon Sep 17 00:00:00 2001 From: Axel Ogereau-Peltier <49279289+axel-op@users.noreply.github.com> Date: Sun, 5 Jul 2020 00:15:58 +0200 Subject: [PATCH] Update tests --- packages/firebase_crashlytics/pubspec.yaml | 1 + .../test/firebase_crashlytics_test.dart | 46 ++++++++++--------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/packages/firebase_crashlytics/pubspec.yaml b/packages/firebase_crashlytics/pubspec.yaml index 8969fc284f8d..7c48f583aac4 100644 --- a/packages/firebase_crashlytics/pubspec.yaml +++ b/packages/firebase_crashlytics/pubspec.yaml @@ -22,6 +22,7 @@ dev_dependencies: test: ^1.5.1 flutter_driver: sdk: flutter + path: ^1.6.4 flutter: plugin: diff --git a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart index cd5f551fd1cf..672eb3d5471c 100644 --- a/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart +++ b/packages/firebase_crashlytics/test/firebase_crashlytics_test.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:path/path.dart' as path; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -25,6 +26,8 @@ void main() { case 'Crashlytics#onError': return 'Error reported to Crashlytics.'; case 'Crashlytics#setUserIdentifier': + case 'Crashlytics#setKey': + case 'Crashlytics#log': return true; default: return false; @@ -33,6 +36,25 @@ void main() { log.clear(); }); + test('log', () async { + crashlytics.enableInDevMode = true; + final msg = 'foo'; + await crashlytics.log(msg); + expect(log[0].method, 'Crashlytics#log'); + expect(log[0].arguments['log'], msg); + }); + + test('setKeys', () async { + crashlytics.enableInDevMode = true; + final key = 'testKey'; + // All values are converted to Strings by Dart code + final value = 'testValue'; + await crashlytics.setCustomKey(key, value); + expect(log[0].method, 'Crashlytics#setKey'); + expect(log[0].arguments['key'], key); + expect(log[0].arguments['value'], value); + }); + test('recordFlutterError', () async { final FlutterErrorDetails details = FlutterErrorDetails( exception: 'foo exception', @@ -44,29 +66,16 @@ void main() { ], context: ErrorDescription('foo context'), ); - crashlytics - ..enableInDevMode = true - ..log('foo') - ..setCustomKey('testBool', true) - ..setCustomKey('testInt', 42) - ..setCustomKey('testDouble', 42.0) - ..setCustomKey('testString', 'bar'); + crashlytics.enableInDevMode = true; await crashlytics.recordFlutterError(details); expect(log[0].method, 'Crashlytics#onError'); expect(log[0].arguments['exception'], 'foo exception'); expect(log[0].arguments['context'], 'foo context'); expect(log[0].arguments['information'], 'test message\nsecond message'); - expect(log[0].arguments['logs'], isNotEmpty); - expect(log[0].arguments['logs'], contains('foo')); - expect(log[0].arguments['keys']['testBool'], 'true'); - expect(log[0].arguments['keys']['testInt'], '42'); - expect(log[0].arguments['keys']['testDouble'], '42.0'); - expect(log[0].arguments['keys']['testString'], 'bar'); }); test('recordError', () async { crashlytics.enableInDevMode = true; - crashlytics.log('foo'); await crashlytics.recordError('foo exception', null, context: "context"); expect(log[0].method, 'Crashlytics#onError'); expect(log[0].arguments['exception'], 'foo exception'); @@ -74,14 +83,9 @@ void main() { // Confirm that the stack trace contains current stack. expect( log[0].arguments['stackTraceElements'], - contains(containsPair('file', 'firebase_crashlytics_test.dart')), + contains(containsPair( + 'file', path.join('test', 'firebase_crashlytics_test.dart'))), ); - expect(log[0].arguments['logs'], isNotEmpty); - expect(log[0].arguments['logs'], contains('foo')); - expect(log[0].arguments['keys']['testBool'], 'true'); - expect(log[0].arguments['keys']['testInt'], '42'); - expect(log[0].arguments['keys']['testDouble'], '42.0'); - expect(log[0].arguments['keys']['testString'], 'bar'); }); test('crash', () {