From 3263ffdf6c89afefa8c6d718a87007fa811490ec Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Sat, 14 Sep 2024 22:08:53 +0200 Subject: [PATCH] fix tests --- dart/test/debug_image_extractor_test.dart | 3 +- .../enricher/io_enricher_test.dart | 5 +- .../enricher/web_enricher_test.dart | 4 +- dart/test/sentry_client_test.dart | 4 +- dart/test/sentry_test.dart | 12 +- dart/test/stack_trace_test.dart | 3 +- dart/test/test_utils.dart | 5 +- ...flutter_enricher_event_processor_test.dart | 9 +- flutter/test/initialization_test.dart | 13 +- .../debug_print_integration_test.dart | 3 +- .../flutter_error_integration_test.dart | 8 + .../integrations/init_native_sdk_test.dart | 2 +- .../on_error_integration_test.dart | 8 + flutter/test/mocks.dart | 11 +- flutter/test/mocks.mocks.dart | 251 ++++++++++++++++-- flutter/test/replay/replay_native_test.dart | 7 +- flutter/test/sentry_flutter_options_test.dart | 8 +- flutter/test/sentry_flutter_test.dart | 113 +++----- flutter/test/sentry_native_channel_test.dart | 6 +- 19 files changed, 328 insertions(+), 147 deletions(-) diff --git a/dart/test/debug_image_extractor_test.dart b/dart/test/debug_image_extractor_test.dart index 8801da6e65..7a0ad7d12f 100644 --- a/dart/test/debug_image_extractor_test.dart +++ b/dart/test/debug_image_extractor_test.dart @@ -112,8 +112,7 @@ isolate_dso_base: 10000000 class Fixture { DebugImageExtractor getSut({required MockPlatform platform}) { - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(platform: platform); + final options = defaultTestOptions(MockPlatformChecker(platform: platform)); return DebugImageExtractor(options); } } diff --git a/dart/test/event_processor/enricher/io_enricher_test.dart b/dart/test/event_processor/enricher/io_enricher_test.dart index 1df1f58169..a48c8dfed5 100644 --- a/dart/test/event_processor/enricher/io_enricher_test.dart +++ b/dart/test/event_processor/enricher/io_enricher_test.dart @@ -186,9 +186,8 @@ class Fixture { bool hasNativeIntegration = false, bool includePii = false, }) { - final options = defaultTestOptions() - ..platformChecker = - MockPlatformChecker(hasNativeIntegration: hasNativeIntegration) + final options = defaultTestOptions( + MockPlatformChecker(hasNativeIntegration: hasNativeIntegration)) ..sendDefaultPii = includePii; return IoEnricherEventProcessor(options); diff --git a/dart/test/event_processor/enricher/web_enricher_test.dart b/dart/test/event_processor/enricher/web_enricher_test.dart index c8089a72e4..39502fc134 100644 --- a/dart/test/event_processor/enricher/web_enricher_test.dart +++ b/dart/test/event_processor/enricher/web_enricher_test.dart @@ -202,8 +202,8 @@ void main() { class Fixture { WebEnricherEventProcessor getSut() { - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); return enricherEventProcessor(options) as WebEnricherEventProcessor; } } diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 109a93cb61..cf3df91d13 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -1896,8 +1896,8 @@ class Fixture { final recorder = MockClientReportRecorder(); final transport = MockTransport(); - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(platform: MockPlatform.iOS()); + final options = + defaultTestOptions(MockPlatformChecker(platform: MockPlatform.iOS())); late SentryTransactionContext _context; late SentryTracer tracer; diff --git a/dart/test/sentry_test.dart b/dart/test/sentry_test.dart index 56db9152fd..201062ed5d 100644 --- a/dart/test/sentry_test.dart +++ b/dart/test/sentry_test.dart @@ -372,8 +372,7 @@ void main() { }); test('options.environment debug', () async { - final sentryOptions = defaultTestOptions() - ..platformChecker = FakePlatformChecker.debugMode(); + final sentryOptions = defaultTestOptions(FakePlatformChecker.debugMode()); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -385,8 +384,7 @@ void main() { }); test('options.environment profile', () async { - final sentryOptions = defaultTestOptions() - ..platformChecker = FakePlatformChecker.profileMode(); + final sentryOptions = defaultTestOptions(FakePlatformChecker.profileMode()); await Sentry.init( (options) { @@ -399,8 +397,7 @@ void main() { }); test('options.environment production (defaultEnvironment)', () async { - final sentryOptions = defaultTestOptions() - ..platformChecker = FakePlatformChecker.releaseMode(); + final sentryOptions = defaultTestOptions(FakePlatformChecker.releaseMode()); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -412,8 +409,7 @@ void main() { }); test('options.logger is set by setting the debug flag', () async { - final sentryOptions = defaultTestOptions() - ..platformChecker = FakePlatformChecker.debugMode(); + final sentryOptions = defaultTestOptions(FakePlatformChecker.debugMode()); await Sentry.init( (options) { diff --git a/dart/test/stack_trace_test.dart b/dart/test/stack_trace_test.dart index 35251c32af..f63bc0f227 100644 --- a/dart/test/stack_trace_test.dart +++ b/dart/test/stack_trace_test.dart @@ -299,8 +299,7 @@ class Fixture { bool considerInAppFramesByDefault = true, bool isWeb = false, }) { - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(isWebValue: isWeb); + final options = defaultTestOptions(MockPlatformChecker(isWebValue: isWeb)); inAppIncludes.forEach(options.addInAppInclude); inAppExcludes.forEach(options.addInAppExclude); options.considerInAppFramesByDefault = considerInAppFramesByDefault; diff --git a/dart/test/test_utils.dart b/dart/test/test_utils.dart index 507226cb1e..ec25b32f85 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -18,8 +18,9 @@ const String _testDsnWithPath = const String _testDsnWithPort = 'https://public:secret@sentry.example.com:8888/1'; -SentryOptions defaultTestOptions() { - return SentryOptions(dsn: testDsn)..automatedTestMode = true; +SentryOptions defaultTestOptions([PlatformChecker? checker]) { + return SentryOptions(dsn: testDsn, checker: checker) + ..automatedTestMode = true; } void testHeaders( diff --git a/flutter/test/event_processor/flutter_enricher_event_processor_test.dart b/flutter/test/event_processor/flutter_enricher_event_processor_test.dart index 20a1b99bc4..0873bd3b22 100644 --- a/flutter/test/event_processor/flutter_enricher_event_processor_test.dart +++ b/flutter/test/event_processor/flutter_enricher_event_processor_test.dart @@ -368,9 +368,9 @@ void main() { testWidgets('$FlutterEnricherEventProcessor gets added on init', (tester) async { - final sentryOptions = defaultTestOptions() - // use a mockplatform checker so that we don't need to mock platform channels - ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); + // use a mockplatform checker so that we don't need to mock platform channels + final sentryOptions = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); loadTestPackage(); await SentryFlutter.init((options) { @@ -417,8 +417,7 @@ class Fixture { hasNativeIntegration: hasNativeIntegration, ); - final options = defaultTestOptions() - ..platformChecker = platformChecker + final options = defaultTestOptions(platformChecker) ..reportPackages = reportPackages; final customizedOptions = optionsBuilder?.call(options) ?? options; return FlutterEnricherEventProcessor(customizedOptions); diff --git a/flutter/test/initialization_test.dart b/flutter/test/initialization_test.dart index 3feee15746..d36e549339 100644 --- a/flutter/test/initialization_test.dart +++ b/flutter/test/initialization_test.dart @@ -10,25 +10,22 @@ import 'mocks.dart'; // https://github.com/getsentry/sentry-dart/issues/508 // There are no asserts, test are succesfull if no exceptions are thrown. void main() { - setUp(() async { - await Sentry.close(); - }); + final native = NativeChannelFixture(); void optionsInitializer(SentryFlutterOptions options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; - // LoadReleaseIntegration throws because package_info channel is not available options.removeIntegration( options.integrations.firstWhere((i) => i is LoadReleaseIntegration)); } test('async re-initilization', () async { - await SentryFlutter.init(optionsInitializer); + await SentryFlutter.init(optionsInitializer, + options: defaultTestOptions()..methodChannel = native.channel); await Sentry.close(); - await SentryFlutter.init(optionsInitializer); + await SentryFlutter.init(optionsInitializer, + options: defaultTestOptions()..methodChannel = native.channel); await Sentry.close(); }); diff --git a/flutter/test/integrations/debug_print_integration_test.dart b/flutter/test/integrations/debug_print_integration_test.dart index 2cde8eb9b5..67359ade71 100644 --- a/flutter/test/integrations/debug_print_integration_test.dart +++ b/flutter/test/integrations/debug_print_integration_test.dart @@ -94,8 +94,7 @@ class Fixture { bool debug = false, bool enablePrintBreadcrumbs = true, }) { - return defaultTestOptions() - ..platformChecker = MockPlatformChecker(isDebug: debug) + return defaultTestOptions(MockPlatformChecker(isDebug: debug)) ..enablePrintBreadcrumbs = enablePrintBreadcrumbs; } diff --git a/flutter/test/integrations/flutter_error_integration_test.dart b/flutter/test/integrations/flutter_error_integration_test.dart index 0294afa6d4..4ec10025cb 100644 --- a/flutter/test/integrations/flutter_error_integration_test.dart +++ b/flutter/test/integrations/flutter_error_integration_test.dart @@ -269,6 +269,14 @@ void main() { final hub = Hub(fixture.options); final client = MockSentryClient(); + when(client.captureEvent(any, + scope: anyNamed('scope'), + stackTrace: anyNamed('stackTrace'), + hint: anyNamed('hint'))) + .thenAnswer((_) => Future.value(SentryId.newId())); + when(client.captureTransaction(any, + scope: anyNamed('scope'), traceContext: anyNamed('traceContext'))) + .thenAnswer((_) => Future.value(SentryId.newId())); hub.bindClient(client); final sut = fixture.getSut(); diff --git a/flutter/test/integrations/init_native_sdk_test.dart b/flutter/test/integrations/init_native_sdk_test.dart index e475a08e56..6f84e946f5 100644 --- a/flutter/test/integrations/init_native_sdk_test.dart +++ b/flutter/test/integrations/init_native_sdk_test.dart @@ -189,7 +189,7 @@ MethodChannel createChannelWithCallback( SentryFlutterOptions createOptions() { final mockPlatformChecker = MockPlatformChecker(hasNativeIntegration: true); - final options = defaultTestOptions()..platformChecker = mockPlatformChecker; + final options = defaultTestOptions(mockPlatformChecker); options.sdk = SdkVersion( name: sdkName, version: sdkVersion, diff --git a/flutter/test/integrations/on_error_integration_test.dart b/flutter/test/integrations/on_error_integration_test.dart index b1a2dc090f..f367916612 100644 --- a/flutter/test/integrations/on_error_integration_test.dart +++ b/flutter/test/integrations/on_error_integration_test.dart @@ -164,6 +164,14 @@ void main() { final hub = Hub(fixture.options); final client = MockSentryClient(); + when(client.captureEvent(any, + scope: anyNamed('scope'), + stackTrace: anyNamed('stackTrace'), + hint: anyNamed('hint'))) + .thenAnswer((_) => Future.value(SentryId.newId())); + when(client.captureTransaction(any, + scope: anyNamed('scope'), traceContext: anyNamed('traceContext'))) + .thenAnswer((_) => Future.value(SentryId.newId())); hub.bindClient(client); final sut = fixture.getSut(); diff --git a/flutter/test/mocks.dart b/flutter/test/mocks.dart index effd4013fd..fd14b71d2e 100644 --- a/flutter/test/mocks.dart +++ b/flutter/test/mocks.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/src/widgets/binding.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; import 'package:sentry/src/platform/platform.dart'; import 'package:sentry/src/sentry_tracer.dart'; @@ -18,8 +19,9 @@ import 'no_such_method_provider.dart'; const fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; const fakeProguardUuid = '3457d982-65ef-576d-a6ad-65b5f30f49a5'; -SentryFlutterOptions defaultTestOptions() { - return SentryFlutterOptions(dsn: fakeDsn)..automatedTestMode = true; +SentryFlutterOptions defaultTestOptions([PlatformChecker? checker]) { + return SentryFlutterOptions(dsn: fakeDsn, checker: checker) + ..automatedTestMode = true; } // https://github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md#fallback-generators @@ -44,6 +46,7 @@ ISentrySpan startTransactionShim( SentryTracer, SentryTransaction, SentrySpan, + SentryClient, MethodChannel, SentryNativeBinding ], customMocks: [ @@ -166,8 +169,6 @@ class TestBindingWrapper implements BindingWrapper { } } -class MockSentryClient with NoSuchMethodProvider implements SentryClient {} - // All these values are based on the fakeFrameDurations list. // The expected total frames is also based on the span duration of 1000ms and the slow and frozen frames. const expectedTotalFrames = 17; @@ -199,6 +200,8 @@ class NativeChannelFixture { TestWidgetsFlutterBinding.ensureInitialized(); channel = MethodChannel('test.channel', StandardMethodCodec(), _messenger); handler = MockCallbacks().methodCallHandler; + when(handler('initNativeSdk', any)).thenAnswer((_) => Future.value()); + when(handler('closeNativeSdk', any)).thenAnswer((_) => Future.value()); _messenger.setMockMethodCallHandler( channel, (call) => handler(call.method, call.arguments)); } diff --git a/flutter/test/mocks.mocks.dart b/flutter/test/mocks.mocks.dart index feb97b5927..3f94ca0274 100644 --- a/flutter/test/mocks.mocks.dart +++ b/flutter/test/mocks.mocks.dart @@ -4,19 +4,19 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i7; -import 'dart:typed_data' as _i12; +import 'dart:typed_data' as _i13; import 'package:flutter/services.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i8; -import 'package:sentry/src/metrics/metric.dart' as _i14; +import 'package:sentry/src/metrics/metric.dart' as _i10; import 'package:sentry/src/metrics/metrics_api.dart' as _i5; import 'package:sentry/src/profiling.dart' as _i9; import 'package:sentry/src/sentry_tracer.dart' as _i3; import 'package:sentry_flutter/sentry_flutter.dart' as _i2; -import 'package:sentry_flutter/src/native/native_app_start.dart' as _i11; -import 'package:sentry_flutter/src/native/native_frames.dart' as _i13; -import 'package:sentry_flutter/src/native/sentry_native_binding.dart' as _i10; +import 'package:sentry_flutter/src/native/native_app_start.dart' as _i12; +import 'package:sentry_flutter/src/native/native_frames.dart' as _i14; +import 'package:sentry_flutter/src/native/sentry_native_binding.dart' as _i11; import 'mocks.dart' as _i6; @@ -280,6 +280,12 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValueForMissingStub: null, ); + @override + Map get measurements => (super.noSuchMethod( + Invocation.getter(#measurements), + returnValue: {}, + ) as Map); + @override _i2.SentrySpanContext get context => (super.noSuchMethod( Invocation.getter(#context), @@ -349,12 +355,6 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValue: {}, ) as Map); - @override - Map get measurements => (super.noSuchMethod( - Invocation.getter(#measurements), - returnValue: {}, - ) as Map); - @override _i7.Future finish({ _i2.SpanStatus? status, @@ -519,6 +519,24 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValueForMissingStub: null, ); + @override + void setMeasurementFromChild( + String? name, + num? value, { + _i2.SentryMeasurementUnit? unit, + }) => + super.noSuchMethod( + Invocation.method( + #setMeasurementFromChild, + [ + name, + value, + ], + {#unit: unit}, + ), + returnValueForMissingStub: null, + ); + @override void scheduleFinish() => super.noSuchMethod( Invocation.method( @@ -998,6 +1016,189 @@ class MockSentrySpan extends _i1.Mock implements _i2.SentrySpan { ); } +/// A class which mocks [SentryClient]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockSentryClient extends _i1.Mock implements _i2.SentryClient { + MockSentryClient() { + _i1.throwOnMissingStub(this); + } + + @override + _i7.Future<_i2.SentryId> captureEvent( + _i2.SentryEvent? event, { + _i2.Scope? scope, + dynamic stackTrace, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureEvent, + [event], + { + #scope: scope, + #stackTrace: stackTrace, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureEvent, + [event], + { + #scope: scope, + #stackTrace: stackTrace, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureException( + dynamic throwable, { + dynamic stackTrace, + _i2.Scope? scope, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #scope: scope, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #scope: scope, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureMessage( + String? formatted, { + _i2.SentryLevel? level, + String? template, + List? params, + _i2.Scope? scope, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureMessage, + [formatted], + { + #level: level, + #template: template, + #params: params, + #scope: scope, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureMessage, + [formatted], + { + #level: level, + #template: template, + #params: params, + #scope: scope, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureTransaction( + _i2.SentryTransaction? transaction, { + _i2.Scope? scope, + _i2.SentryTraceContextHeader? traceContext, + }) => + (super.noSuchMethod( + Invocation.method( + #captureTransaction, + [transaction], + { + #scope: scope, + #traceContext: traceContext, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureTransaction, + [transaction], + { + #scope: scope, + #traceContext: traceContext, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId?> captureEnvelope(_i2.SentryEnvelope? envelope) => + (super.noSuchMethod( + Invocation.method( + #captureEnvelope, + [envelope], + ), + returnValue: _i7.Future<_i2.SentryId?>.value(), + ) as _i7.Future<_i2.SentryId?>); + + @override + _i7.Future captureUserFeedback(_i2.SentryUserFeedback? userFeedback) => + (super.noSuchMethod( + Invocation.method( + #captureUserFeedback, + [userFeedback], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future<_i2.SentryId> captureMetrics( + Map>? metricsBuckets) => + (super.noSuchMethod( + Invocation.method( + #captureMetrics, + [metricsBuckets], + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureMetrics, + [metricsBuckets], + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + /// A class which mocks [MethodChannel]. /// /// See the documentation for Mockito's code generation for more information. @@ -1097,7 +1298,7 @@ class MockMethodChannel extends _i1.Mock implements _i4.MethodChannel { /// /// See the documentation for Mockito's code generation for more information. class MockSentryNativeBinding extends _i1.Mock - implements _i10.SentryNativeBinding { + implements _i11.SentryNativeBinding { MockSentryNativeBinding() { _i1.throwOnMissingStub(this); } @@ -1123,17 +1324,17 @@ class MockSentryNativeBinding extends _i1.Mock ) as _i7.Future); @override - _i7.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( + _i7.Future<_i12.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( Invocation.method( #fetchNativeAppStart, [], ), - returnValue: _i7.Future<_i11.NativeAppStart?>.value(), - ) as _i7.Future<_i11.NativeAppStart?>); + returnValue: _i7.Future<_i12.NativeAppStart?>.value(), + ) as _i7.Future<_i12.NativeAppStart?>); @override _i7.Future captureEnvelope( - _i12.Uint8List? envelopeData, + _i13.Uint8List? envelopeData, bool? containsUnhandledException, ) => (super.noSuchMethod( @@ -1159,14 +1360,14 @@ class MockSentryNativeBinding extends _i1.Mock ) as _i7.Future); @override - _i7.Future<_i13.NativeFrames?> endNativeFrames(_i2.SentryId? id) => + _i7.Future<_i14.NativeFrames?> endNativeFrames(_i2.SentryId? id) => (super.noSuchMethod( Invocation.method( #endNativeFrames, [id], ), - returnValue: _i7.Future<_i13.NativeFrames?>.value(), - ) as _i7.Future<_i13.NativeFrames?>); + returnValue: _i7.Future<_i14.NativeFrames?>.value(), + ) as _i7.Future<_i14.NativeFrames?>); @override _i7.Future setUser(_i2.SentryUser? user) => (super.noSuchMethod( @@ -1363,6 +1564,16 @@ class MockSentryNativeBinding extends _i1.Mock returnValueForMissingStub: _i7.Future.value(), ) as _i7.Future); + @override + _i7.Future nativeCrash() => (super.noSuchMethod( + Invocation.method( + #nativeCrash, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + @override _i7.Future<_i2.SentryId> captureReplay(bool? isCrash) => (super.noSuchMethod( Invocation.method( @@ -1715,7 +1926,7 @@ class MockHub extends _i1.Mock implements _i2.Hub { @override _i7.Future<_i2.SentryId> captureMetrics( - Map>? metricsBuckets) => + Map>? metricsBuckets) => (super.noSuchMethod( Invocation.method( #captureMetrics, diff --git a/flutter/test/replay/replay_native_test.dart b/flutter/test/replay/replay_native_test.dart index 44493d0f97..560c04b44e 100644 --- a/flutter/test/replay/replay_native_test.dart +++ b/flutter/test/replay/replay_native_test.dart @@ -58,13 +58,8 @@ void main() { ..createSync(recursive: true); native = NativeChannelFixture(); - when(native.handler('initNativeSdk', any)) - .thenAnswer((_) => Future.value()); - when(native.handler('closeNativeSdk', any)) - .thenAnswer((_) => Future.value()); - options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(mockPlatform: mockPlatform) + options = defaultTestOptions(MockPlatformChecker(mockPlatform: mockPlatform)) ..fileSystem = fs ..methodChannel = native.channel; diff --git a/flutter/test/sentry_flutter_options_test.dart b/flutter/test/sentry_flutter_options_test.dart index 6b09b0d89f..7c4d2e79b1 100644 --- a/flutter/test/sentry_flutter_options_test.dart +++ b/flutter/test/sentry_flutter_options_test.dart @@ -6,8 +6,8 @@ void main() { group('SentryFlutterOptions', () { testWidgets('auto breadcrumb tracking: has native integration', (WidgetTester tester) async { - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(hasNativeIntegration: true); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: true)); expect(options.enableAppLifecycleBreadcrumbs, isFalse); expect(options.enableWindowMetricBreadcrumbs, isFalse); @@ -19,8 +19,8 @@ void main() { testWidgets('auto breadcrumb tracking: without native integration', (WidgetTester tester) async { - final options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); expect(options.enableAppLifecycleBreadcrumbs, isTrue); expect(options.enableWindowMetricBreadcrumbs, isTrue); diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 641723a33a..085da245f9 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -59,10 +59,6 @@ void main() { setUp(() async { native = NativeChannelFixture(); - when(native.handler('initNativeSdk', any)) - .thenAnswer((_) => Future.value()); - when(native.handler('closeNativeSdk', any)) - .thenAnswer((_) => Future.value()); }); group('Test platform integrations', () { @@ -76,10 +72,9 @@ void main() { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = - getPlatformChecker(platform: MockPlatform.android()); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -132,9 +127,9 @@ void main() { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker(platform: MockPlatform.iOs()); + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.iOs())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -184,9 +179,9 @@ void main() { test('macOS', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker(platform: MockPlatform.macOs()); + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.macOs())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -232,10 +227,9 @@ void main() { test('Windows', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = - getPlatformChecker(platform: MockPlatform.windows()); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.windows())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -284,9 +278,9 @@ void main() { test('Linux', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker(platform: MockPlatform.linux()); + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.linux())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -335,12 +329,9 @@ void main() { test('Web', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker( - isWeb: true, - platform: MockPlatform.linux(), - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.linux())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { @@ -388,12 +379,9 @@ void main() { test('Web && (iOS || macOS)', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker( - isWeb: true, - platform: MockPlatform.iOs(), - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.iOs())) + ..methodChannel = native.channel; // Tests that iOS || macOS integrations aren't added on a browser which // runs on iOS or macOS @@ -436,12 +424,9 @@ void main() { test('Web && (macOS)', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker( - isWeb: true, - platform: MockPlatform.macOs(), - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.macOs())) + ..methodChannel = native.channel; // Tests that iOS || macOS integrations aren't added on a browser which // runs on iOS or macOS @@ -486,12 +471,9 @@ void main() { test('Web && Android', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = defaultTestOptions() - ..methodChannel = native.channel - ..platformChecker = getPlatformChecker( - isWeb: true, - platform: MockPlatform.android(), - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.android())) + ..methodChannel = native.channel; // Tests that Android integrations aren't added on an Android browser await SentryFlutter.init( @@ -539,10 +521,9 @@ void main() { test('installed on io platforms', () async { List integrations = []; - final sentryFlutterOptions = defaultTestOptions() + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.iOs(), isWeb: false)) ..methodChannel = native.channel - ..platformChecker = - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: false) ..rendererWrapper = MockRendererWrapper(FlutterRenderer.skia); await SentryFlutter.init( @@ -565,9 +546,8 @@ void main() { test('installed with canvasKit renderer', () async { List integrations = []; - final sentryFlutterOptions = defaultTestOptions() - ..platformChecker = - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true) + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true)) ..rendererWrapper = MockRendererWrapper(FlutterRenderer.canvasKit); await SentryFlutter.init( @@ -590,9 +570,8 @@ void main() { test('not installed with html renderer', () async { List integrations = []; - final sentryFlutterOptions = defaultTestOptions() - ..platformChecker = - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true) + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true)) ..rendererWrapper = MockRendererWrapper(FlutterRenderer.html); await SentryFlutter.init( @@ -620,15 +599,11 @@ void main() { }); test('test that initial values are set correctly', () async { - final sentryFlutterOptions = defaultTestOptions() - ..platformChecker = getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); await SentryFlutter.init( (options) { - expect(false, options.debug); expect('debug', options.environment); expect(sdkName, options.sdk.name); @@ -646,15 +621,11 @@ void main() { test( 'enablePureDartSymbolication is set to false during SentryFlutter init', () async { - final sentryFlutterOptions = defaultTestOptions() - ..platformChecker = getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); SentryFlutter.native = MockSentryNativeBinding(); await SentryFlutter.init( (options) { - expect(options.enableDartSymbolication, false); }, appRunner: appRunner, @@ -712,14 +683,10 @@ void main() { test( 'should add DartExceptionTypeIdentifier and FlutterExceptionTypeIdentifier by default', () async { - final actualOptions = defaultTestOptions() - ..platformChecker = getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ); + final actualOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); await SentryFlutter.init( - (options) { - }, + (options) {}, appRunner: appRunner, options: actualOptions, ); diff --git a/flutter/test/sentry_native_channel_test.dart b/flutter/test/sentry_native_channel_test.dart index ba933e8937..0428349d49 100644 --- a/flutter/test/sentry_native_channel_test.dart +++ b/flutter/test/sentry_native_channel_test.dart @@ -28,9 +28,9 @@ void main() { setUp(() { channel = MockMethodChannel(); - final options = defaultTestOptions() - ..platformChecker = getPlatformChecker(platform: mockPlatform) - ..methodChannel = channel; + final options = + defaultTestOptions(getPlatformChecker(platform: mockPlatform)) + ..methodChannel = channel; sut = createBinding(options); });