Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-op committed Jul 4, 2020
1 parent 1b8cdb9 commit f9100e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/firebase_crashlytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dev_dependencies:
test: ^1.5.1
flutter_driver:
sdk: flutter
path: ^1.6.4

flutter:
plugin:
Expand Down
46 changes: 25 additions & 21 deletions packages/firebase_crashlytics/test/firebase_crashlytics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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',
Expand All @@ -44,44 +66,26 @@ 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');
expect(log[0].arguments['context'], "context");
// 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', () {
Expand Down

0 comments on commit f9100e2

Please sign in to comment.