diff --git a/dart/test/debug_image_extractor_test.dart b/dart/test/debug_image_extractor_test.dart index 6218c726a9..8801da6e65 100644 --- a/dart/test/debug_image_extractor_test.dart +++ b/dart/test/debug_image_extractor_test.dart @@ -1,9 +1,9 @@ import 'package:test/test.dart'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/debug_image_extractor.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group(DebugImageExtractor, () { @@ -112,7 +112,7 @@ isolate_dso_base: 10000000 class Fixture { DebugImageExtractor getSut({required MockPlatform platform}) { - final options = SentryOptions(dsn: 'https://public@sentry.example.com/1') + final options = defaultTestOptions() ..platformChecker = MockPlatformChecker(platform: platform); return DebugImageExtractor(options); } diff --git a/dart/test/diagnostic_logger_test.dart b/dart/test/diagnostic_logger_test.dart index ec53421e33..f33baa1643 100644 --- a/dart/test/diagnostic_logger_test.dart +++ b/dart/test/diagnostic_logger_test.dart @@ -2,6 +2,8 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/diagnostic_logger.dart'; import 'package:test/test.dart'; +import 'test_utils.dart'; + void main() { late Fixture fixture; @@ -44,7 +46,7 @@ void main() { } class Fixture { - var options = SentryOptions(); + var options = defaultTestOptions(); Object? loggedMessage; diff --git a/dart/test/environment_test.dart b/dart/test/environment_test.dart index b16225d1dd..edc366d3aa 100644 --- a/dart/test/environment_test.dart +++ b/dart/test/environment_test.dart @@ -3,6 +3,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_environment_variables.dart'; +import 'test_utils.dart'; void main() { // See https://docs.sentry.io/platforms/dart/configuration/options/ @@ -13,7 +14,7 @@ void main() { }); test('SentryOptions are not overriden by environment', () async { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.release = 'release-1.2.3'; options.dist = 'foo'; options.environment = 'prod'; @@ -23,7 +24,6 @@ void main() { release: 'release-9.8.7', dist: 'bar', ); - options.automatedTestMode = true; await Sentry.init( (options) => options, @@ -37,14 +37,13 @@ void main() { }); test('SentryOptions are overriden by environment', () async { - final options = SentryOptions(); + final options = defaultTestOptions(); options.environmentVariables = MockEnvironmentVariables( dsn: fakeDsn, environment: 'staging', release: 'release-9.8.7', dist: 'bar', ); - options.automatedTestMode = true; await Sentry.init( (options) => options, diff --git a/dart/test/event_processor/deduplication_event_processor_test.dart b/dart/test/event_processor/deduplication_event_processor_test.dart index 3e17fe4065..de576bafd4 100644 --- a/dart/test/event_processor/deduplication_event_processor_test.dart +++ b/dart/test/event_processor/deduplication_event_processor_test.dart @@ -6,6 +6,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_hub.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; void main() { group('$DeduplicationEventProcessor', () { @@ -77,14 +78,13 @@ void main() { final transport = MockTransport(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; await Sentry.init( (options) { options.dsn = fakeDsn; options.transport = transport; options.enableDeduplication = true; }, - options: options, + options: defaultTestOptions(), ); // The test doesn't work if `outerTestMethod` is passed as @@ -114,7 +114,7 @@ class Fixture { DeduplicationEventProcessor getSut(bool enabled, [int? maxDeduplicationItems]) { - final options = SentryOptions(dsn: fakeDsn) + final options = defaultTestOptions() ..enableDeduplication = enabled ..maxDeduplicationItems = maxDeduplicationItems ?? 5; diff --git a/dart/test/event_processor/enricher/io_enricher_test.dart b/dart/test/event_processor/enricher/io_enricher_test.dart index dad1a62f6c..1df1f58169 100644 --- a/dart/test/event_processor/enricher/io_enricher_test.dart +++ b/dart/test/event_processor/enricher/io_enricher_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import '../../mocks.dart'; import '../../mocks/mock_platform_checker.dart'; +import '../../test_utils.dart'; void main() { group('io_enricher', () { @@ -164,20 +165,17 @@ void main() { }); test('$IoEnricherEventProcessor gets added on init', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; - late SentryOptions configuredOptions; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; - configuredOptions = options; }, options: options, ); await Sentry.close(); - final ioEnricherCount = configuredOptions.eventProcessors - .whereType() - .length; + final ioEnricherCount = + options.eventProcessors.whereType().length; expect(ioEnricherCount, 1); }); }); @@ -188,10 +186,9 @@ class Fixture { bool hasNativeIntegration = false, bool includePii = false, }) { - final options = SentryOptions( - dsn: fakeDsn, - checker: - MockPlatformChecker(hasNativeIntegration: hasNativeIntegration)) + final options = defaultTestOptions() + ..platformChecker = + MockPlatformChecker(hasNativeIntegration: hasNativeIntegration) ..sendDefaultPii = includePii; return IoEnricherEventProcessor(options); diff --git a/dart/test/event_processor/enricher/io_platform_memory_test.dart b/dart/test/event_processor/enricher/io_platform_memory_test.dart index 0f987b935c..ce2c8474f4 100644 --- a/dart/test/event_processor/enricher/io_platform_memory_test.dart +++ b/dart/test/event_processor/enricher/io_platform_memory_test.dart @@ -3,10 +3,11 @@ library dart_test; import 'dart:io'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/event_processor/enricher/io_platform_memory.dart'; import 'package:test/test.dart'; +import '../../test_utils.dart'; + void main() { late Fixture fixture; @@ -52,7 +53,7 @@ void main() { } class Fixture { - var options = SentryOptions(); + var options = defaultTestOptions(); PlatformMemory getSut() { return PlatformMemory(options); diff --git a/dart/test/event_processor/enricher/web_enricher_test.dart b/dart/test/event_processor/enricher/web_enricher_test.dart index d2590a09fa..c8089a72e4 100644 --- a/dart/test/event_processor/enricher/web_enricher_test.dart +++ b/dart/test/event_processor/enricher/web_enricher_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import '../../mocks.dart'; import '../../mocks/mock_platform_checker.dart'; +import '../../test_utils.dart'; // can be tested on command line with // `dart test -p chrome --name web_enricher` @@ -201,9 +202,8 @@ void main() { class Fixture { WebEnricherEventProcessor getSut() { - final options = SentryOptions( - dsn: fakeDsn, - checker: MockPlatformChecker(hasNativeIntegration: false)); + final options = defaultTestOptions() + ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); return enricherEventProcessor(options) as WebEnricherEventProcessor; } } diff --git a/dart/test/exception_identifier_test.dart b/dart/test/exception_identifier_test.dart index b3014203dd..29e2a4a735 100644 --- a/dart/test/exception_identifier_test.dart +++ b/dart/test/exception_identifier_test.dart @@ -4,10 +4,10 @@ import 'package:sentry/src/dart_exception_type_identifier.dart'; import 'package:sentry/src/sentry_exception_factory.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks.mocks.dart'; import 'mocks/mock_transport.dart'; import 'sentry_client_test.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -165,7 +165,7 @@ void main() { } class Fixture { - SentryOptions options = SentryOptions(dsn: fakeDsn); + SentryOptions options = defaultTestOptions(); } // We use this PlaceHolder exception to mimic an obfuscated runtimeType diff --git a/dart/test/http_client/failed_request_client_test.dart b/dart/test/http_client/failed_request_client_test.dart index 2ac9a74c8e..b35dd2957b 100644 --- a/dart/test/http_client/failed_request_client_test.dart +++ b/dart/test/http_client/failed_request_client_test.dart @@ -8,6 +8,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_hub.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; final requestUri = Uri.parse('https://example.com?foo=bar#myFragment'); @@ -359,7 +360,7 @@ MockClient createThrowingClient() { class CloseableMockClient extends Mock implements BaseClient {} class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dart/test/http_client/io_client_provider_test.dart b/dart/test/http_client/io_client_provider_test.dart index 0672e84c08..81d05c1540 100644 --- a/dart/test/http_client/io_client_provider_test.dart +++ b/dart/test/http_client/io_client_provider_test.dart @@ -7,7 +7,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/http_client/io_client_provider.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; void main() { group('getClient', () { @@ -77,7 +77,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final mockHttpClient = MockHttpClient(); String? mockUser; diff --git a/dart/test/http_client/tracing_client_test.dart b/dart/test/http_client/tracing_client_test.dart index 6cefe626b3..4e052dc518 100644 --- a/dart/test/http_client/tracing_client_test.dart +++ b/dart/test/http_client/tracing_client_test.dart @@ -5,8 +5,8 @@ import 'package:sentry/src/http_client/tracing_client.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; final requestUri = Uri.parse('https://example.com?foo=bar#baz'); @@ -220,7 +220,7 @@ MockClient createThrowingClient() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dart/test/hub_test.dart b/dart/test/hub_test.dart index c53ab74e48..5fef36c2b9 100644 --- a/dart/test/hub_test.dart +++ b/dart/test/hub_test.dart @@ -10,6 +10,7 @@ import 'mocks.dart'; import 'mocks.mocks.dart'; import 'mocks/mock_client_report_recorder.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { bool scopeEquals(Scope? a, Scope b) { @@ -25,7 +26,7 @@ void main() { group('Hub instantiation', () { test('should instantiate with a dsn', () { - final hub = Hub(SentryOptions(dsn: fakeDsn)); + final hub = Hub(defaultTestOptions()); expect(hub.isEnabled, true); }); }); @@ -458,11 +459,11 @@ void main() { }); group('Hub scope', () { - var hub = Hub(SentryOptions(dsn: fakeDsn)); + var hub = Hub(defaultTestOptions()); var client = MockSentryClient(); setUp(() { - hub = Hub(SentryOptions(dsn: fakeDsn)); + hub = Hub(defaultTestOptions()); client = MockSentryClient(); hub.bindClient(client); }); @@ -487,7 +488,7 @@ void main() { expect(client.captureEventCalls.first.scope, isNotNull); final scope = client.captureEventCalls.first.scope; - final otherScope = Scope(SentryOptions(dsn: fakeDsn)) + final otherScope = Scope(defaultTestOptions()) ..level = SentryLevel.debug ..fingerprint = ['1', '2']; @@ -511,7 +512,7 @@ void main() { await hub.captureEvent(fakeEvent); final scope = client.captureEventCalls.first.scope; - final otherScope = Scope(SentryOptions(dsn: fakeDsn)); + final otherScope = Scope(defaultTestOptions()); await otherScope.setUser(fakeUser); expect( @@ -593,7 +594,7 @@ void main() { SentryOptions options; setUp(() { - options = SentryOptions(dsn: fakeDsn); + options = defaultTestOptions(); hub = Hub(options); client = MockSentryClient(); hub.bindClient(client); @@ -756,7 +757,7 @@ class Fixture { final client = MockSentryClient(); final recorder = MockClientReportRecorder(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late SentryTransactionContext _context; late SentryTracer tracer; diff --git a/dart/test/initialization_test.dart b/dart/test/initialization_test.dart index e6f9ddea23..42766ac93d 100644 --- a/dart/test/initialization_test.dart +++ b/dart/test/initialization_test.dart @@ -5,6 +5,7 @@ import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; import 'mocks.dart'; +import 'test_utils.dart'; // Tests for the following issue // https://github.com/getsentry/sentry-dart/issues/508 @@ -15,7 +16,7 @@ void main() { }); test('async re-initilization', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -36,7 +37,7 @@ void main() { // This is the failure from // https://github.com/getsentry/sentry-dart/issues/508 test('re-initilization', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; diff --git a/dart/test/load_dart_debug_images_integration_test.dart b/dart/test/load_dart_debug_images_integration_test.dart index 8b10a62328..e7f06525ce 100644 --- a/dart/test/load_dart_debug_images_integration_test.dart +++ b/dart/test/load_dart_debug_images_integration_test.dart @@ -7,6 +7,7 @@ import 'package:test/test.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group(LoadDartDebugImagesIntegration, () { @@ -92,7 +93,7 @@ isolate_dso_base: 10000000 } class Fixture { - final options = SentryOptions(dsn: 'https://public@sentry.example.com/1'); + final options = defaultTestOptions(); Fixture() { final integration = LoadDartDebugImagesIntegration(); diff --git a/dart/test/metrics/metrics_aggregator_test.dart b/dart/test/metrics/metrics_aggregator_test.dart index 5636e7ebf6..f42a7ef2cf 100644 --- a/dart/test/metrics/metrics_aggregator_test.dart +++ b/dart/test/metrics/metrics_aggregator_test.dart @@ -3,8 +3,8 @@ import 'package:sentry/src/metrics/metric.dart'; import 'package:sentry/src/metrics/metrics_aggregator.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { group('emit', () { @@ -455,7 +455,7 @@ const Map mockTags2 = {'tag1': 'val1'}; final DateTime mockTimestamp = DateTime.fromMillisecondsSinceEpoch(1); class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final mockHub = MockHub(); late final hub = Hub(options); diff --git a/dart/test/metrics/metrics_api_test.dart b/dart/test/metrics/metrics_api_test.dart index 8c53e66772..8e18d21996 100644 --- a/dart/test/metrics/metrics_api_test.dart +++ b/dart/test/metrics/metrics_api_test.dart @@ -6,8 +6,8 @@ import 'package:sentry/src/metrics/metrics_api.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { group('api', () { @@ -144,7 +144,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); final mockHub = MockHub(); late final hub = Hub(_options); diff --git a/dart/test/mocks/mock_hub.dart b/dart/test/mocks/mock_hub.dart index c076251736..8fa7d31388 100644 --- a/dart/test/mocks/mock_hub.dart +++ b/dart/test/mocks/mock_hub.dart @@ -3,7 +3,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/metrics/metric.dart'; import 'package:sentry/src/metrics/metrics_aggregator.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; import 'mock_sentry_client.dart'; import 'no_such_method_provider.dart'; @@ -21,7 +21,7 @@ class MockHub with NoSuchMethodProvider implements Hub { int spanContextCals = 0; int getSpanCalls = 0; - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late final MetricsAggregator _metricsAggregator = MetricsAggregator(options: _options, hub: this); diff --git a/dart/test/protocol/rate_limiter_test.dart b/dart/test/protocol/rate_limiter_test.dart index b4364bceff..96d91ea685 100644 --- a/dart/test/protocol/rate_limiter_test.dart +++ b/dart/test/protocol/rate_limiter_test.dart @@ -10,6 +10,7 @@ import 'package:sentry/src/sentry_envelope_header.dart'; import '../mocks/mock_client_report_recorder.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { var fixture = Fixture(); @@ -368,7 +369,7 @@ class Fixture { late var mockRecorder = MockClientReportRecorder(); RateLimiter getSut() { - final options = SentryOptions(); + final options = defaultTestOptions(); options.clock = _currentDateTime; options.recorder = mockRecorder; diff --git a/dart/test/recursive_exception_cause_extractor_test.dart b/dart/test/recursive_exception_cause_extractor_test.dart index e32400b36b..c1422fdc88 100644 --- a/dart/test/recursive_exception_cause_extractor_test.dart +++ b/dart/test/recursive_exception_cause_extractor_test.dart @@ -2,10 +2,9 @@ import 'package:sentry/src/exception_cause.dart'; import 'package:sentry/src/exception_cause_extractor.dart'; import 'package:sentry/src/recursive_exception_cause_extractor.dart'; import 'package:sentry/src/protocol/mechanism.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:sentry/src/throwable_mechanism.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -101,7 +100,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); RecursiveExceptionCauseExtractor getSut() { return RecursiveExceptionCauseExtractor(options); diff --git a/dart/test/run_zoned_guarded_integration_test.dart b/dart/test/run_zoned_guarded_integration_test.dart index dd3c2aa0f3..71f87e9d12 100644 --- a/dart/test/run_zoned_guarded_integration_test.dart +++ b/dart/test/run_zoned_guarded_integration_test.dart @@ -4,9 +4,9 @@ library dart_test; import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group(RunZonedGuardedIntegration, () { @@ -77,7 +77,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; RunZonedGuardedIntegration getSut( {required RunZonedGuardedRunner runner, diff --git a/dart/test/scope_test.dart b/dart/test/scope_test.dart index 0059a2e77a..9519e97390 100644 --- a/dart/test/scope_test.dart +++ b/dart/test/scope_test.dart @@ -8,6 +8,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_scope_observer.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -426,7 +427,7 @@ void main() { tags: const {'etag': '987'}, extra: const {'e-infos': 'abc'}, ); - final scope = Scope(SentryOptions(dsn: fakeDsn)) + final scope = Scope(defaultTestOptions()) ..fingerprint = ['example-dart'] ..transaction = '/example/app' ..level = SentryLevel.warning @@ -454,8 +455,7 @@ void main() { test('apply trace context to event', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..span = fixture.sentryTracer; + final scope = Scope(defaultTestOptions())..span = fixture.sentryTracer; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -473,7 +473,7 @@ void main() { fingerprint: ['event-fingerprint'], breadcrumbs: [eventBreadcrumb], ); - final scope = Scope(SentryOptions(dsn: fakeDsn)) + final scope = Scope(defaultTestOptions()) ..fingerprint = ['example-dart'] ..transaction = '/example/app'; @@ -502,7 +502,7 @@ void main() { operatingSystem: SentryOperatingSystem(name: 'event-os'), ), ); - final scope = Scope(SentryOptions(dsn: fakeDsn)); + final scope = Scope(defaultTestOptions()); await scope.setContexts( SentryDevice.type, SentryDevice(name: 'context-device'), @@ -542,7 +542,7 @@ void main() { test('should apply the scope.contexts values', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)); + final scope = Scope(defaultTestOptions()); await scope.setContexts( SentryDevice.type, SentryDevice(name: 'context-device')); await scope.setContexts(SentryApp.type, SentryApp(name: 'context-app')); @@ -580,8 +580,7 @@ void main() { test('should apply the scope level', () async { final event = SentryEvent(level: SentryLevel.warning); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -590,8 +589,7 @@ void main() { test('should apply the scope transaction from the span', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..span = fixture.sentryTracer; + final scope = Scope(defaultTestOptions())..span = fixture.sentryTracer; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -612,7 +610,7 @@ void main() { test('should not apply fingerprint if transaction', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..fingerprint = ['test']; + final scope = Scope(defaultTestOptions())..fingerprint = ['test']; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -621,7 +619,7 @@ void main() { test('should not apply level if transaction', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -630,7 +628,7 @@ void main() { test('apply sampled to trace', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -776,7 +774,7 @@ void main() { class Fixture { final mockScopeObserver = MockScopeObserver(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final sentryTracer = SentryTracer( SentryTransactionContext( diff --git a/dart/test/sentry_attachment_test.dart b/dart/test/sentry_attachment_test.dart index 578cb5ad9b..267ca62601 100644 --- a/dart/test/sentry_attachment_test.dart +++ b/dart/test/sentry_attachment_test.dart @@ -3,8 +3,8 @@ import 'dart:typed_data'; import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('$SentryAttachment ctor', () { @@ -185,7 +185,7 @@ class Fixture { MockTransport transport = MockTransport(); Hub getSut() { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.transport = transport; return Hub(options); } diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 07d5aab834..fff6379088 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -24,6 +24,7 @@ import 'mocks/mock_hub.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('SentryClient captures message', () { @@ -1884,7 +1885,7 @@ class Fixture { final recorder = MockClientReportRecorder(); final transport = MockTransport(); - final options = SentryOptions(dsn: fakeDsn) + final options = defaultTestOptions() ..platformChecker = MockPlatformChecker(platform: MockPlatform.iOS()); late SentryTransactionContext _context; diff --git a/dart/test/sentry_envelope_test.dart b/dart/test/sentry_envelope_test.dart index a24cab20c7..7fe59d099d 100644 --- a/dart/test/sentry_envelope_test.dart +++ b/dart/test/sentry_envelope_test.dart @@ -10,6 +10,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { group('SentryEnvelope', () { @@ -51,7 +52,9 @@ void main() { '$expectedHeaderJsonSerialized\n$expectedItemSerialized\n$expectedItemSerialized'); final envelopeData = []; - await sut.envelopeStream(SentryOptions()).forEach(envelopeData.addAll); + await sut + .envelopeStream(defaultTestOptions()) + .forEach(envelopeData.addAll); expect(envelopeData, expected); }); @@ -213,12 +216,12 @@ void main() { final sutEnvelopeData = []; await sut - .envelopeStream(SentryOptions()..maxAttachmentSize = 1) + .envelopeStream(defaultTestOptions()..maxAttachmentSize = 1) .forEach(sutEnvelopeData.addAll); final envelopeData = []; await expectedEnvelopeItem - .envelopeStream(SentryOptions()) + .envelopeStream(defaultTestOptions()) .forEach(envelopeData.addAll); expect(sutEnvelopeData, envelopeData); @@ -238,7 +241,7 @@ void main() { dsn: fakeDsn, ); - final _ = sut.envelopeStream(SentryOptions()).map((e) => e); + final _ = sut.envelopeStream(defaultTestOptions()).map((e) => e); }); }); } diff --git a/dart/test/sentry_envelope_vm_test.dart b/dart/test/sentry_envelope_vm_test.dart index 7854ffccb0..e5f0276704 100644 --- a/dart/test/sentry_envelope_vm_test.dart +++ b/dart/test/sentry_envelope_vm_test.dart @@ -10,6 +10,7 @@ import 'package:sentry/src/sentry_envelope_item_header.dart'; import 'package:test/test.dart'; import 'mocks.dart'; +import 'test_utils.dart'; void main() { group('SentryEnvelopeItem', () { @@ -37,7 +38,7 @@ void main() { final envelopeData = []; await envelope - .envelopeStream(SentryOptions()) + .envelopeStream(defaultTestOptions()) .forEach(envelopeData.addAll); final expectedEnvelopeFile = @@ -62,8 +63,9 @@ void main() { attachments: [attachment], ); - final data = (await envelope.envelopeStream(SentryOptions()).toList()) - .reduce((a, b) => a + b); + final data = + (await envelope.envelopeStream(defaultTestOptions()).toList()) + .reduce((a, b) => a + b); final file = File('test_resources/envelope-no-attachment.envelope'); final jsonStr = await file.readAsString(); diff --git a/dart/test/sentry_exception_factory_test.dart b/dart/test/sentry_exception_factory_test.dart index cca350f2b4..a3129fb8f3 100644 --- a/dart/test/sentry_exception_factory_test.dart +++ b/dart/test/sentry_exception_factory_test.dart @@ -2,7 +2,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_exception_factory.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { final fixture = Fixture(); @@ -284,7 +284,7 @@ isolate_instructions: 7526344980, vm_instructions: 752633f000 } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); SentryExceptionFactory getSut({bool attachStacktrace = true}) { options.attachStacktrace = true; diff --git a/dart/test/sentry_isolate_extension_test.dart b/dart/test/sentry_isolate_extension_test.dart index 626d7e525c..89c6a0fe4b 100644 --- a/dart/test/sentry_isolate_extension_test.dart +++ b/dart/test/sentry_isolate_extension_test.dart @@ -4,11 +4,10 @@ library dart_test; import 'dart:isolate'; import 'package:sentry/src/sentry_isolate_extension.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { group("SentryIsolate", () { @@ -53,7 +52,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; Isolate getSut() { return Isolate.current; diff --git a/dart/test/sentry_isolate_test.dart b/dart/test/sentry_isolate_test.dart index 6d41636303..07347d5585 100644 --- a/dart/test/sentry_isolate_test.dart +++ b/dart/test/sentry_isolate_test.dart @@ -5,12 +5,11 @@ import 'package:sentry/src/hub.dart'; import 'package:sentry/src/protocol/sentry_level.dart'; import 'package:sentry/src/protocol/span_status.dart'; import 'package:sentry/src/sentry_isolate.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group("SentryIsolate", () { @@ -72,5 +71,5 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; } diff --git a/dart/test/sentry_options_test.dart b/dart/test/sentry_options_test.dart index bb2db9db24..be652ca91c 100644 --- a/dart/test/sentry_options_test.dart +++ b/dart/test/sentry_options_test.dart @@ -4,16 +4,16 @@ import 'package:sentry/src/noop_client.dart'; import 'package:sentry/src/version.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { test('$Client is NoOp', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(NoOpClient(), options.httpClient); }); test('$Client sets a custom client', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final client = Client(); options.httpClient = client; @@ -21,20 +21,20 @@ void main() { }); test('maxBreadcrumbs is 100 by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(100, options.maxBreadcrumbs); }); test('maxBreadcrumbs sets custom maxBreadcrumbs', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.maxBreadcrumbs = 200; expect(200, options.maxBreadcrumbs); }); test('SentryLogger sets a diagnostic logger', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); // ignore: deprecated_member_use_from_same_package expect(options.logger, noOpLogger); // ignore: deprecated_member_use_from_same_package @@ -45,32 +45,32 @@ void main() { }); test('tracesSampler is null by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.tracesSampler, isNull); }); test('tracesSampleRate is null by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.tracesSampleRate, isNull); }); test('isTracingEnabled is disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.isTracingEnabled(), false); }); test('isTracingEnabled is enabled by theres rate', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.tracesSampleRate = 1.0; expect(options.isTracingEnabled(), true); }); test('isTracingEnabled is enabled by theres sampler', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); double? sampler(SentrySamplingContext samplingContext) => 0.0; @@ -98,7 +98,7 @@ void main() { }); test('SentryOptions has sentryClientName set', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.sentryClientName, '${sdkName(options.platformChecker.isWeb)}/$sdkVersion'); @@ -131,39 +131,39 @@ void main() { }); test('Spotlight is disabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.spotlight.enabled, false); }); test('metrics are disabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableMetrics, false); }); test('enableExceptionTypeIdentification is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableExceptionTypeIdentification, true); }); test('default tags for metrics are enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; expect(options.enableDefaultTagsForMetrics, true); }); test('default tags for metrics are disabled if metrics are disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = false; expect(options.enableDefaultTagsForMetrics, false); }); test('default tags for metrics are enabled if metrics are enabled, too', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; options.enableDefaultTagsForMetrics = true; @@ -171,14 +171,14 @@ void main() { }); test('span local metric aggregation is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; expect(options.enableSpanLocalMetricAggregation, true); }); test('span local metric aggregation is disabled if metrics are disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = false; expect(options.enableSpanLocalMetricAggregation, false); @@ -186,7 +186,7 @@ void main() { test('span local metric aggregation is enabled if metrics are enabled, too', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; options.enableSpanLocalMetricAggregation = true; @@ -194,7 +194,7 @@ void main() { }); test('enablePureDartSymbolication is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableDartSymbolication, true); }); diff --git a/dart/test/sentry_test.dart b/dart/test/sentry_test.dart index 1b363b99a0..56db9152fd 100644 --- a/dart/test/sentry_test.dart +++ b/dart/test/sentry_test.dart @@ -9,6 +9,7 @@ import 'fake_platform_checker.dart'; import 'mocks.dart'; import 'mocks/mock_integration.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; AppRunner appRunner = () {}; @@ -19,7 +20,7 @@ void main() { var anException = Exception(); setUp(() async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -142,7 +143,7 @@ void main() { }); test('null DSN', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); expect( () async => await Sentry.init( options: options, @@ -155,7 +156,7 @@ void main() { test('appRunner should be optional', () async { expect(Sentry.isEnabled, false); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = fakeDsn, @@ -164,7 +165,7 @@ void main() { }); test('empty DSN', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = '', @@ -175,7 +176,7 @@ void main() { test('empty DSN disables the SDK but runs the integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -188,7 +189,7 @@ void main() { }); test('close disables the SDK', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = fakeDsn, @@ -212,7 +213,7 @@ void main() { test('should install integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -226,7 +227,7 @@ void main() { test('should add default integrations', () async { late SentryOptions optionsReference; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -250,7 +251,7 @@ void main() { }, onPlatform: {'browser': Skip()}); test('should add only web compatible default integrations', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -266,7 +267,7 @@ void main() { test('should close integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -282,7 +283,7 @@ void main() { }); test('$DeduplicationEventProcessor is added on init', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -299,7 +300,7 @@ void main() { final completer = Completer(); var completed = false; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); final init = Sentry.init( options: options, (options) { @@ -321,7 +322,7 @@ void main() { }); test('should add DartExceptionTypeIdentifier by default', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -348,7 +349,7 @@ void main() { final completer = Completer(); var completed = false; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); final init = Sentry.init( options: options, (options) { @@ -371,12 +372,8 @@ void main() { }); test('options.environment debug', () async { - final sentryOptions = SentryOptions(dsn: fakeDsn) - ..automatedTestMode = true + final sentryOptions = defaultTestOptions() ..platformChecker = FakePlatformChecker.debugMode(); - - final options = SentryOptions(); - options.automatedTestMode = true; await Sentry.init( (options) { options.dsn = fakeDsn; @@ -388,9 +385,8 @@ void main() { }); test('options.environment profile', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.profileMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions() + ..platformChecker = FakePlatformChecker.profileMode(); await Sentry.init( (options) { @@ -403,9 +399,8 @@ void main() { }); test('options.environment production (defaultEnvironment)', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.releaseMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions() + ..platformChecker = FakePlatformChecker.releaseMode(); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -417,9 +412,8 @@ void main() { }); test('options.logger is set by setting the debug flag', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.debugMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions() + ..platformChecker = FakePlatformChecker.debugMode(); await Sentry.init( (options) { @@ -443,7 +437,7 @@ void main() { final fixture = Fixture(); test('throw is handled and logged', () async { - final sentryOptions = SentryOptions(dsn: fakeDsn) + final sentryOptions = defaultTestOptions() ..automatedTestMode = false ..debug = true ..logger = fixture.mockLogger; diff --git a/dart/test/sentry_tracer_test.dart b/dart/test/sentry_tracer_test.dart index ba57aeb405..121cba3def 100644 --- a/dart/test/sentry_tracer_test.dart +++ b/dart/test/sentry_tracer_test.dart @@ -2,9 +2,9 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group('$SentryTracer', () { @@ -608,7 +608,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn) + final options = defaultTestOptions() ..release = 'release' ..environment = 'environment'; diff --git a/dart/test/sentry_traces_sampler_test.dart b/dart/test/sentry_traces_sampler_test.dart index 276897e651..2d3d08c734 100644 --- a/dart/test/sentry_traces_sampler_test.dart +++ b/dart/test/sentry_traces_sampler_test.dart @@ -2,7 +2,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_traces_sampler.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -151,7 +151,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); SentryLevel? loggedLevel; Object? loggedException; diff --git a/dart/test/sentry_transaction_test.dart b/dart/test/sentry_transaction_test.dart index 7de0549a13..8457e6eb4d 100644 --- a/dart/test/sentry_transaction_test.dart +++ b/dart/test/sentry_transaction_test.dart @@ -4,6 +4,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { final fixture = Fixture(); @@ -108,7 +109,7 @@ void main() { } class Fixture { - final SentryOptions options = SentryOptions(dsn: fakeDsn); + final SentryOptions options = defaultTestOptions(); late final Hub hub = Hub(options); SentryTransaction getSut(SentryTracer tracer) { diff --git a/dart/test/sentry_user_feedback_test.dart b/dart/test/sentry_user_feedback_test.dart index cb406f65b1..4c9e7fdab2 100644 --- a/dart/test/sentry_user_feedback_test.dart +++ b/dart/test/sentry_user_feedback_test.dart @@ -5,6 +5,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('$SentryUserFeedback', () { @@ -141,7 +142,7 @@ void main() { }); test('captureUserFeedback does not throw', () async { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final transport = ThrowingTransport(); options.transport = transport; final sut = Hub(options); @@ -158,7 +159,7 @@ class Fixture { late MockTransport transport; Hub getSut() { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); transport = MockTransport(); options.transport = transport; return Hub(options); diff --git a/dart/test/stack_trace_test.dart b/dart/test/stack_trace_test.dart index 3636d845a4..35251c32af 100644 --- a/dart/test/stack_trace_test.dart +++ b/dart/test/stack_trace_test.dart @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sentry/sentry.dart'; import 'package:sentry/src/origin.dart'; import 'package:sentry/src/sentry_stack_trace_factory.dart'; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group('encodeStackTraceFrame', () { @@ -300,8 +299,8 @@ class Fixture { bool considerInAppFramesByDefault = true, bool isWeb = false, }) { - final options = SentryOptions( - dsn: fakeDsn, checker: MockPlatformChecker(isWebValue: isWeb)); + final options = defaultTestOptions() + ..platformChecker = 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 c7a0138a76..507226cb1e 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -18,6 +18,10 @@ const String _testDsnWithPath = const String _testDsnWithPort = 'https://public:secret@sentry.example.com:8888/1'; +SentryOptions defaultTestOptions() { + return SentryOptions(dsn: testDsn)..automatedTestMode = true; +} + void testHeaders( Map? headers, ClockProvider fakeClockProvider, { @@ -69,7 +73,7 @@ Future testCaptureException( fail('Unexpected request on ${request.method} ${request.url} in HttpMock'); }); - final options = SentryOptions(dsn: testDsn) + final options = defaultTestOptions() ..compressPayload = compressPayload ..clock = fakeClockProvider ..httpClient = httpMock @@ -196,7 +200,7 @@ Future testCaptureException( void runTest({Codec, List?>? gzip, bool isWeb = false}) { test('can parse DSN', () async { - final options = SentryOptions(dsn: testDsn); + final options = defaultTestOptions(); final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -213,7 +217,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); test('can parse DSN without secret', () async { - final options = SentryOptions(dsn: _testDsnWithoutSecret); + final options = defaultTestOptions()..dsn = _testDsnWithoutSecret; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -230,7 +234,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); test('can parse DSN with path', () async { - final options = SentryOptions(dsn: _testDsnWithPath); + final options = defaultTestOptions()..dsn = _testDsnWithPath; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -246,7 +250,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { client.close(); }); test('can parse DSN with port', () async { - final options = SentryOptions(dsn: _testDsnWithPort); + final options = defaultTestOptions()..dsn = _testDsnWithPort; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -277,7 +281,8 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); final client = SentryClient( - SentryOptions(dsn: _testDsnWithoutSecret) + defaultTestOptions() + ..dsn = _testDsnWithoutSecret ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false @@ -331,9 +336,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); final client = SentryClient( - SentryOptions( - dsn: testDsn, - ) + defaultTestOptions() ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false @@ -392,9 +395,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { data: {'foo': 'bar'}, ); - final options = SentryOptions( - dsn: testDsn, - ) + final options = defaultTestOptions() ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false diff --git a/dart/test/transport/http_transport_test.dart b/dart/test/transport/http_transport_test.dart index 90065d89d3..6546cd73eb 100644 --- a/dart/test/transport/http_transport_test.dart +++ b/dart/test/transport/http_transport_test.dart @@ -17,6 +17,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_client_report_recorder.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { SentryEnvelope givenEnvelope() { @@ -286,9 +287,7 @@ void main() { } class Fixture { - final options = SentryOptions( - dsn: 'https://public:secret@sentry.example.com/1', - ); + final options = defaultTestOptions(); late var clientReportRecorder = MockClientReportRecorder(); diff --git a/dart/test/transport/spotlight_http_transport_test.dart b/dart/test/transport/spotlight_http_transport_test.dart index b23f1fd87f..3e9d742bb1 100644 --- a/dart/test/transport/spotlight_http_transport_test.dart +++ b/dart/test/transport/spotlight_http_transport_test.dart @@ -9,6 +9,7 @@ import 'package:test/scaffolding.dart'; import '../mocks.dart'; import '../mocks/mock_client_report_recorder.dart'; +import '../test_utils.dart'; void main() { group('send to Sentry', () { @@ -52,9 +53,7 @@ void main() { } class Fixture { - final options = SentryOptions( - dsn: 'https://public:secret@sentry.example.com/1', - ); + final options = defaultTestOptions(); late var clientReportRecorder = MockClientReportRecorder(); diff --git a/dart/test/transport/tesk_queue_test.dart b/dart/test/transport/tesk_queue_test.dart index 80dc97161c..af22672d97 100644 --- a/dart/test/transport/tesk_queue_test.dart +++ b/dart/test/transport/tesk_queue_test.dart @@ -1,10 +1,9 @@ import 'dart:async'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/transport/task_queue.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; void main() { group("called sync", () { @@ -110,7 +109,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); TaskQueue getSut({required int maxQueueSize}) { return TaskQueue(maxQueueSize, options.logger); diff --git a/dart/test/utils/tracing_utils_test.dart b/dart/test/utils/tracing_utils_test.dart index 96b26b55b1..601d522e27 100644 --- a/dart/test/utils/tracing_utils_test.dart +++ b/dart/test/utils/tracing_utils_test.dart @@ -2,8 +2,8 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_sentry_client.dart'; +import '../test_utils.dart'; void main() { group('$containsTargetOrMatchesRegExp', () { @@ -167,7 +167,7 @@ class Fixture { ), ); - final _options = SentryOptions(dsn: fakeDsn) + final _options = defaultTestOptions() ..release = 'release' ..environment = 'environment'; diff --git a/dio/test/dio_event_processor_test.dart b/dio/test/dio_event_processor_test.dart index af4a94ab8d..9786828841 100644 --- a/dio/test/dio_event_processor_test.dart +++ b/dio/test/dio_event_processor_test.dart @@ -436,7 +436,7 @@ final requestOptions = RequestOptions( ); class Fixture { - final SentryOptions options = SentryOptions(dsn: fakeDsn); + final SentryOptions options = defaultTestOptions(); // ignore: invalid_use_of_internal_member SentryExceptionFactory get exceptionFactory => options.exceptionFactory; diff --git a/dio/test/mocks.dart b/dio/test/mocks.dart index 30e53c5772..052ab82576 100644 --- a/dio/test/mocks.dart +++ b/dio/test/mocks.dart @@ -3,6 +3,11 @@ import 'package:sentry/src/transport/rate_limiter.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + final fakeException = Exception('Error'); final fakeMessage = SentryMessage( diff --git a/dio/test/mocks/mock_hub.dart b/dio/test/mocks/mock_hub.dart index 377e1efb79..5e896d58d7 100644 --- a/dio/test/mocks/mock_hub.dart +++ b/dio/test/mocks/mock_hub.dart @@ -2,6 +2,7 @@ import 'package:meta/meta.dart'; import 'package:sentry/sentry.dart'; +import '../mocks.dart'; import 'no_such_method_provider.dart'; class MockHub with NoSuchMethodProvider implements Hub { @@ -17,7 +18,7 @@ class MockHub with NoSuchMethodProvider implements Hub { int spanContextCals = 0; int getSpanCalls = 0; - final _options = SentryOptions(dsn: 'fixture-dsn'); + final _options = defaultTestOptions(); @override @internal diff --git a/dio/test/sentry_transformer_test.dart b/dio/test/sentry_transformer_test.dart index ffa793c791..93fd36f138 100644 --- a/dio/test/sentry_transformer_test.dart +++ b/dio/test/sentry_transformer_test.dart @@ -137,7 +137,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dio/test/tracing_client_adapter_test.dart b/dio/test/tracing_client_adapter_test.dart index f67ec4c14d..680825b34f 100644 --- a/dio/test/tracing_client_adapter_test.dart +++ b/dio/test/tracing_client_adapter_test.dart @@ -183,7 +183,7 @@ MockHttpClientAdapter createThrowingClient() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/drift/test/sentry_database_test.dart b/drift/test/sentry_database_test.dart index 52b0c9ee28..9028889630 100644 --- a/drift/test/sentry_database_test.dart +++ b/drift/test/sentry_database_test.dart @@ -15,6 +15,7 @@ import 'package:sqlite3/open.dart'; import 'mocks/mocks.mocks.dart'; import 'test_database.dart'; +import 'utils.dart'; import 'utils/windows_helper.dart'; void main() { @@ -643,7 +644,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); static final dbName = 'people-drift-impl'; final exception = Exception('fixture-exception'); diff --git a/drift/test/utils.dart b/drift/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/drift/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/file/test/mock_sentry_client.dart b/file/test/mock_sentry_client.dart index 4a4a28142d..8fb4091cd7 100644 --- a/file/test/mock_sentry_client.dart +++ b/file/test/mock_sentry_client.dart @@ -4,6 +4,11 @@ import 'no_such_method_provider.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + class MockSentryClient with NoSuchMethodProvider implements SentryClient { List captureTransactionCalls = []; diff --git a/file/test/sentry_file_extension_test.dart b/file/test/sentry_file_extension_test.dart index d6a0bff5bc..843de96003 100644 --- a/file/test/sentry_file_extension_test.dart +++ b/file/test/sentry_file_extension_test.dart @@ -46,7 +46,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub hub; File getSut({ diff --git a/file/test/sentry_file_test.dart b/file/test/sentry_file_test.dart index 48cf9b5175..8a1731a96c 100644 --- a/file/test/sentry_file_test.dart +++ b/file/test/sentry_file_test.dart @@ -662,7 +662,7 @@ void main() { class Fixture { final client = MockSentryClient(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub hub; SentryFile getSut( diff --git a/file/test/sentry_io_overrides_integration_test.dart b/file/test/sentry_io_overrides_integration_test.dart index 86d5f25d74..5a0dcc23a5 100644 --- a/file/test/sentry_io_overrides_integration_test.dart +++ b/file/test/sentry_io_overrides_integration_test.dart @@ -68,7 +68,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final hub = Hub(options); SentryIOOverridesIntegration getSut() { diff --git a/flutter/test/android_platform_exception_event_processor_test.dart b/flutter/test/android_platform_exception_event_processor_test.dart index 9ebae071c7..25ea8b2c6b 100644 --- a/flutter/test/android_platform_exception_event_processor_test.dart +++ b/flutter/test/android_platform_exception_event_processor_test.dart @@ -209,8 +209,7 @@ class Fixture { name: 'main', ); - SentryFlutterOptions options = SentryFlutterOptions(dsn: fakeDsn) - ..attachThreads = true; + SentryFlutterOptions options = defaultTestOptions()..attachThreads = true; } final detailsAndStackTracePlatformException = PlatformException( 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 3514c7bc7c..20a1b99bc4 100644 --- a/flutter/test/event_processor/flutter_enricher_event_processor_test.dart +++ b/flutter/test/event_processor/flutter_enricher_event_processor_test.dart @@ -368,7 +368,7 @@ void main() { testWidgets('$FlutterEnricherEventProcessor gets added on init', (tester) async { - final sentryOptions = SentryFlutterOptions() + final sentryOptions = defaultTestOptions() // use a mockplatform checker so that we don't need to mock platform channels ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); @@ -417,10 +417,9 @@ class Fixture { hasNativeIntegration: hasNativeIntegration, ); - final options = SentryFlutterOptions( - dsn: fakeDsn, - checker: platformChecker, - )..reportPackages = reportPackages; + final options = defaultTestOptions() + ..platformChecker = platformChecker + ..reportPackages = reportPackages; final customizedOptions = optionsBuilder?.call(options) ?? options; return FlutterEnricherEventProcessor(customizedOptions); } diff --git a/flutter/test/event_processor/screenshot_event_processor_test.dart b/flutter/test/event_processor/screenshot_event_processor_test.dart index 819e3b9b7b..0b8eb62d46 100644 --- a/flutter/test/event_processor/screenshot_event_processor_test.dart +++ b/flutter/test/event_processor/screenshot_event_processor_test.dart @@ -180,7 +180,7 @@ void main() { class Fixture { late Hub hub; - SentryFlutterOptions options = SentryFlutterOptions(dsn: fakeDsn); + SentryFlutterOptions options = defaultTestOptions(); Fixture() { options.attachScreenshot = true; diff --git a/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart b/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart index 22708b95bb..186858888d 100644 --- a/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart +++ b/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart'; +import '../../mocks.dart'; + void main() { group("ignore allowUrls and denyUrls for non Web", () { late Fixture fixture; @@ -32,7 +34,7 @@ void main() { } class Fixture { - SentryFlutterOptions options = SentryFlutterOptions(); + SentryFlutterOptions options = defaultTestOptions(); UrlFilterEventProcessor getSut() { return UrlFilterEventProcessor(options); } diff --git a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart index 5fb5f7039d..bc80d45e6b 100644 --- a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart +++ b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart'; +import '../../mocks.dart'; + // can be tested on command line with // `flutter test --platform=chrome test/event_processor/url_filter/web_url_filter_event_processor_test.dart` // The URL looks something like this: http://localhost:58551/event_processor/url_filter/web_url_filter_event_processor_test.html @@ -112,7 +114,7 @@ void main() { } class Fixture { - SentryFlutterOptions options = SentryFlutterOptions(); + SentryFlutterOptions options = defaultTestOptions(); UrlFilterEventProcessor getSut() { return UrlFilterEventProcessor(options); } diff --git a/flutter/test/file_system_transport_test.dart b/flutter/test/file_system_transport_test.dart index 5aa0713183..015db34a0e 100644 --- a/flutter/test/file_system_transport_test.dart +++ b/flutter/test/file_system_transport_test.dart @@ -155,7 +155,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); FileSystemTransport getSut() { diff --git a/flutter/test/integrations/connectivity_integration_test.dart b/flutter/test/integrations/connectivity_integration_test.dart index 2f0781e9ec..ed7ca80345 100644 --- a/flutter/test/integrations/connectivity_integration_test.dart +++ b/flutter/test/integrations/connectivity_integration_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/connectivity/connectivity_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -48,7 +47,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); ConnectivityIntegration getSut() { return ConnectivityIntegration(); diff --git a/flutter/test/integrations/debug_print_integration_test.dart b/flutter/test/integrations/debug_print_integration_test.dart index b7804abeeb..2cde8eb9b5 100644 --- a/flutter/test/integrations/debug_print_integration_test.dart +++ b/flutter/test/integrations/debug_print_integration_test.dart @@ -94,10 +94,9 @@ class Fixture { bool debug = false, bool enablePrintBreadcrumbs = true, }) { - return SentryFlutterOptions( - dsn: fakeDsn, - checker: MockPlatformChecker(isDebug: debug), - )..enablePrintBreadcrumbs = enablePrintBreadcrumbs; + return defaultTestOptions() + ..platformChecker = MockPlatformChecker(isDebug: debug) + ..enablePrintBreadcrumbs = enablePrintBreadcrumbs; } DebugPrintIntegration getSut() { diff --git a/flutter/test/integrations/fixture.dart b/flutter/test/integrations/fixture.dart index 19a5ed7904..471c6e42b8 100644 --- a/flutter/test/integrations/fixture.dart +++ b/flutter/test/integrations/fixture.dart @@ -9,13 +9,10 @@ import '../mocks.mocks.dart'; class IntegrationTestFixture { late T sut; late Hub hub; - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); IntegrationTestFixture(T Function(SentryNativeBinding) factory) { - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - hub = Hub(options); sut = factory(binding); } diff --git a/flutter/test/integrations/flutter_error_integration_test.dart b/flutter/test/integrations/flutter_error_integration_test.dart index 40a8ef7c36..0294afa6d4 100644 --- a/flutter/test/integrations/flutter_error_integration_test.dart +++ b/flutter/test/integrations/flutter_error_integration_test.dart @@ -307,7 +307,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; FlutterErrorIntegration getSut() { return FlutterErrorIntegration(); diff --git a/flutter/test/integrations/init_native_sdk_test.dart b/flutter/test/integrations/init_native_sdk_test.dart index e4acb6e312..e475a08e56 100644 --- a/flutter/test/integrations/init_native_sdk_test.dart +++ b/flutter/test/integrations/init_native_sdk_test.dart @@ -189,10 +189,7 @@ MethodChannel createChannelWithCallback( SentryFlutterOptions createOptions() { final mockPlatformChecker = MockPlatformChecker(hasNativeIntegration: true); - final options = SentryFlutterOptions( - dsn: fakeDsn, - checker: mockPlatformChecker, - ); + final options = defaultTestOptions()..platformChecker = mockPlatformChecker; options.sdk = SdkVersion( name: sdkName, version: sdkVersion, diff --git a/flutter/test/integrations/load_contexts_integrations_test.dart b/flutter/test/integrations/load_contexts_integrations_test.dart index a1490b8212..7add3f7929 100644 --- a/flutter/test/integrations/load_contexts_integrations_test.dart +++ b/flutter/test/integrations/load_contexts_integrations_test.dart @@ -6,6 +6,7 @@ import 'package:mockito/mockito.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/load_contexts_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -424,7 +425,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); LoadContextsIntegration getSut( diff --git a/flutter/test/integrations/load_release_integration_test.dart b/flutter/test/integrations/load_release_integration_test.dart index 0af572bd8b..3d089b03d9 100644 --- a/flutter/test/integrations/load_release_integration_test.dart +++ b/flutter/test/integrations/load_release_integration_test.dart @@ -143,7 +143,7 @@ void main() { } class Fixture { - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); LoadReleaseIntegration getIntegration({Function? loader}) { if (loader != null) { diff --git a/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart b/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart index 41de1e557e..6df7df0d0f 100644 --- a/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart +++ b/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/on_error_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -51,7 +50,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final platformDispatcherWrapper = PlatformDispatcherWrapper(MockPlatformDispatcher()); diff --git a/flutter/test/integrations/not_initialized_widgets_binding_test.dart b/flutter/test/integrations/not_initialized_widgets_binding_test.dart index 50c8b22b49..702071d106 100644 --- a/flutter/test/integrations/not_initialized_widgets_binding_test.dart +++ b/flutter/test/integrations/not_initialized_widgets_binding_test.dart @@ -1,7 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/widgets_binding_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; /// Tests that require `WidgetsFlutterBinding.ensureInitialized();` not @@ -25,5 +25,5 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); } diff --git a/flutter/test/integrations/on_error_integration_test.dart b/flutter/test/integrations/on_error_integration_test.dart index fb08e68a9b..b1a2dc090f 100644 --- a/flutter/test/integrations/on_error_integration_test.dart +++ b/flutter/test/integrations/on_error_integration_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/on_error_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -187,7 +186,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final platformDispatcherWrapper = PlatformDispatcherWrapper(MockPlatformDispatcher()); diff --git a/flutter/test/integrations/screenshot_integration_test.dart b/flutter/test/integrations/screenshot_integration_test.dart index 4bf2252685..cedf8bca43 100644 --- a/flutter/test/integrations/screenshot_integration_test.dart +++ b/flutter/test/integrations/screenshot_integration_test.dart @@ -1,8 +1,8 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/screenshot_event_processor.dart'; import 'package:sentry_flutter/src/integrations/screenshot_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -69,7 +69,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); ScreenshotIntegration getSut({bool attachScreenshot = true}) { options.attachScreenshot = attachScreenshot; diff --git a/flutter/test/integrations/widgets_flutter_binding_integration_test.dart b/flutter/test/integrations/widgets_flutter_binding_integration_test.dart index 72fb406ee9..3ab2a8f89c 100644 --- a/flutter/test/integrations/widgets_flutter_binding_integration_test.dart +++ b/flutter/test/integrations/widgets_flutter_binding_integration_test.dart @@ -1,6 +1,5 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/widgets_flutter_binding_integration.dart'; import '../mocks.dart'; @@ -43,8 +42,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn) - ..bindingUtils = TestBindingWrapper(); + final options = defaultTestOptions()..bindingUtils = TestBindingWrapper(); TestBindingWrapper get testBindingUtils => options.bindingUtils as TestBindingWrapper; diff --git a/flutter/test/mocks.dart b/flutter/test/mocks.dart index ee74889877..041f0b4a64 100644 --- a/flutter/test/mocks.dart +++ b/flutter/test/mocks.dart @@ -18,7 +18,6 @@ import 'no_such_method_provider.dart'; const fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; const fakeProguardUuid = '3457d982-65ef-576d-a6ad-65b5f30f49a5'; -// TODO use this everywhere in tests so that we don't get exceptions swallowed. SentryFlutterOptions defaultTestOptions() { // ignore: invalid_use_of_internal_member return SentryFlutterOptions(dsn: fakeDsn)..automatedTestMode = true; diff --git a/flutter/test/navigation/sentry_display_widget_test.dart b/flutter/test/navigation/sentry_display_widget_test.dart index a0495bfe8d..abbd6e70dc 100644 --- a/flutter/test/navigation/sentry_display_widget_test.dart +++ b/flutter/test/navigation/sentry_display_widget_test.dart @@ -102,8 +102,7 @@ void main() { } class Fixture { - final Hub hub = - Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final Hub hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); late final SentryNavigatorObserver navigatorObserver; final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); diff --git a/flutter/test/navigation/time_to_display_tracker_test.dart b/flutter/test/navigation/time_to_display_tracker_test.dart index 975adb37fd..6e074bac6e 100644 --- a/flutter/test/navigation/time_to_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_display_tracker_test.dart @@ -255,7 +255,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final options = SentryFlutterOptions() + final options = defaultTestOptions() ..dsn = fakeDsn ..tracesSampleRate = 1.0; late final endTimeProvider = ttidEndTimestampProvider(); diff --git a/flutter/test/navigation/time_to_full_display_tracker_test.dart b/flutter/test/navigation/time_to_full_display_tracker_test.dart index 50609f2692..95d5a3ee25 100644 --- a/flutter/test/navigation/time_to_full_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_full_display_tracker_test.dart @@ -65,7 +65,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final hub = Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); final autoFinishAfter = const Duration(seconds: 2); late final endTimestampProvider = fakeTTIDEndTimestampProvider(); diff --git a/flutter/test/navigation/time_to_initial_display_tracker_test.dart b/flutter/test/navigation/time_to_initial_display_tracker_test.dart index 6e55029572..1f85360f55 100644 --- a/flutter/test/navigation/time_to_initial_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_initial_display_tracker_test.dart @@ -179,7 +179,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final hub = Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); late final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); ISentrySpan getTransaction({String? name = "Regular route"}) { diff --git a/flutter/test/profiling_test.dart b/flutter/test/profiling_test.dart index 04ff70d065..5ab944e53f 100644 --- a/flutter/test/profiling_test.dart +++ b/flutter/test/profiling_test.dart @@ -19,7 +19,7 @@ void main() { group('$SentryNativeProfilerFactory', () { Hub hubWithSampleRate(double profilesSampleRate) { - final o = SentryFlutterOptions(dsn: fakeDsn); + final o = defaultTestOptions(); o.platformChecker = getPlatformChecker(platform: MockPlatform.iOs()); o.profilesSampleRate = profilesSampleRate; diff --git a/flutter/test/replay/recorder_test.dart b/flutter/test/replay/recorder_test.dart index 16db1513b5..2df4334c5b 100644 --- a/flutter/test/replay/recorder_test.dart +++ b/flutter/test/replay/recorder_test.dart @@ -6,7 +6,6 @@ library dart_test; import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/replay/recorder.dart'; import 'package:sentry_flutter/src/replay/recorder_config.dart'; @@ -28,7 +27,7 @@ class _Fixture { _Fixture._() { sut = ScreenshotRecorder( ScreenshotRecorderConfig(), - SentryFlutterOptions()..bindingUtils = TestBindingWrapper(), + defaultTestOptions()..bindingUtils = TestBindingWrapper(), ); } diff --git a/flutter/test/replay/scheduled_recorder_test.dart b/flutter/test/replay/scheduled_recorder_test.dart index f859b27d53..7ace54c18e 100644 --- a/flutter/test/replay/scheduled_recorder_test.dart +++ b/flutter/test/replay/scheduled_recorder_test.dart @@ -6,7 +6,6 @@ library dart_test; import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/replay/scheduled_recorder.dart'; import 'package:sentry_flutter/src/replay/recorder_config.dart'; @@ -45,7 +44,7 @@ class _Fixture { (Image image) async { capturedImages.add("${image.width}x${image.height}"); }, - SentryFlutterOptions()..bindingUtils = TestBindingWrapper(), + defaultTestOptions()..bindingUtils = TestBindingWrapper(), ); } diff --git a/flutter/test/screenshot/sentry_screenshot_widget_test.dart b/flutter/test/screenshot/sentry_screenshot_widget_test.dart index 0b6df7ffad..bedbfe8f1f 100644 --- a/flutter/test/screenshot/sentry_screenshot_widget_test.dart +++ b/flutter/test/screenshot/sentry_screenshot_widget_test.dart @@ -53,7 +53,7 @@ void main() { } class Fixture { - final _options = SentryFlutterOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub hub; SentryScreenshotWidget getSut({ diff --git a/flutter/test/sentry_asset_bundle_test.dart b/flutter/test/sentry_asset_bundle_test.dart index c5236f674a..cd17f3e279 100644 --- a/flutter/test/sentry_asset_bundle_test.dart +++ b/flutter/test/sentry_asset_bundle_test.dart @@ -516,7 +516,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); final assetBundle = TestAssetBundle(); diff --git a/flutter/test/sentry_flutter_options_test.dart b/flutter/test/sentry_flutter_options_test.dart index ed4a3ea7f7..6b09b0d89f 100644 --- a/flutter/test/sentry_flutter_options_test.dart +++ b/flutter/test/sentry_flutter_options_test.dart @@ -1,6 +1,4 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import 'mocks.dart'; @@ -8,8 +6,8 @@ void main() { group('SentryFlutterOptions', () { testWidgets('auto breadcrumb tracking: has native integration', (WidgetTester tester) async { - final options = SentryFlutterOptions( - checker: MockPlatformChecker(hasNativeIntegration: true)); + final options = defaultTestOptions() + ..platformChecker = MockPlatformChecker(hasNativeIntegration: true); expect(options.enableAppLifecycleBreadcrumbs, isFalse); expect(options.enableWindowMetricBreadcrumbs, isFalse); @@ -21,8 +19,8 @@ void main() { testWidgets('auto breadcrumb tracking: without native integration', (WidgetTester tester) async { - final options = SentryFlutterOptions( - checker: MockPlatformChecker(hasNativeIntegration: false)); + final options = defaultTestOptions() + ..platformChecker = MockPlatformChecker(hasNativeIntegration: false); expect(options.enableAppLifecycleBreadcrumbs, isTrue); expect(options.enableWindowMetricBreadcrumbs, isTrue); @@ -33,7 +31,7 @@ void main() { }); testWidgets('useNativeBreadcrumbTracking', (WidgetTester tester) async { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); options.useNativeBreadcrumbTracking(); expect(options.enableAppLifecycleBreadcrumbs, isFalse); @@ -45,7 +43,7 @@ void main() { }); testWidgets('useFlutterBreadcrumbTracking', (WidgetTester tester) async { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); options.useFlutterBreadcrumbTracking(); expect(options.enableAppLifecycleBreadcrumbs, isTrue); diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 551c774d00..641723a33a 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -76,7 +76,7 @@ void main() { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.android()); @@ -84,7 +84,6 @@ void main() { await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -133,14 +132,13 @@ void main() { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.iOs()); await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -186,14 +184,13 @@ void main() { test('macOS', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.macOs()); await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -235,7 +232,7 @@ void main() { test('Windows', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.windows()); @@ -243,7 +240,6 @@ void main() { await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -288,14 +284,13 @@ void main() { test('Linux', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.linux()); await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -340,7 +335,7 @@ void main() { test('Web', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker( isWeb: true, @@ -349,8 +344,6 @@ void main() { await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; @@ -395,7 +388,7 @@ void main() { test('Web && (iOS || macOS)', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker( isWeb: true, @@ -406,8 +399,6 @@ void main() { // runs on iOS or macOS await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, @@ -445,7 +436,7 @@ void main() { test('Web && (macOS)', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker( isWeb: true, @@ -456,8 +447,6 @@ void main() { // runs on iOS or macOS await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, @@ -497,7 +486,7 @@ void main() { test('Web && Android', () async { List integrations = []; Transport transport = MockTransport(); - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker( isWeb: true, @@ -507,8 +496,6 @@ void main() { // Tests that Android integrations aren't added on an Android browser await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, @@ -552,7 +539,7 @@ void main() { test('installed on io platforms', () async { List integrations = []; - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..methodChannel = native.channel ..platformChecker = getPlatformChecker(platform: MockPlatform.iOs(), isWeb: false) @@ -560,8 +547,6 @@ void main() { await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, @@ -580,15 +565,13 @@ void main() { test('installed with canvasKit renderer', () async { List integrations = []; - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..platformChecker = getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true) ..rendererWrapper = MockRendererWrapper(FlutterRenderer.canvasKit); await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, @@ -607,15 +590,13 @@ void main() { test('not installed with html renderer', () async { List integrations = []; - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..platformChecker = getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true) ..rendererWrapper = MockRendererWrapper(FlutterRenderer.html); await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, @@ -639,7 +620,7 @@ void main() { }); test('test that initial values are set correctly', () async { - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..platformChecker = getPlatformChecker( platform: MockPlatform.android(), isWeb: true, @@ -647,8 +628,6 @@ void main() { await SentryFlutter.init( (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; expect(false, options.debug); expect('debug', options.environment); @@ -667,7 +646,7 @@ void main() { test( 'enablePureDartSymbolication is set to false during SentryFlutter init', () async { - final sentryFlutterOptions = SentryFlutterOptions() + final sentryFlutterOptions = defaultTestOptions() ..platformChecker = getPlatformChecker( platform: MockPlatform.android(), isWeb: true, @@ -675,8 +654,6 @@ void main() { SentryFlutter.native = MockSentryNativeBinding(); await SentryFlutter.init( (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; expect(options.enableDartSymbolication, false); }, @@ -735,15 +712,13 @@ void main() { test( 'should add DartExceptionTypeIdentifier and FlutterExceptionTypeIdentifier by default', () async { - final actualOptions = SentryFlutterOptions() + final actualOptions = defaultTestOptions() ..platformChecker = getPlatformChecker( platform: MockPlatform.android(), isWeb: true, ); await SentryFlutter.init( (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; }, appRunner: appRunner, options: actualOptions, diff --git a/flutter/test/sentry_native_channel_test.dart b/flutter/test/sentry_native_channel_test.dart index 86693232d3..ba933e8937 100644 --- a/flutter/test/sentry_native_channel_test.dart +++ b/flutter/test/sentry_native_channel_test.dart @@ -28,10 +28,8 @@ void main() { setUp(() { channel = MockMethodChannel(); - final options = SentryFlutterOptions( - dsn: fakeDsn, checker: getPlatformChecker(platform: mockPlatform)) - // ignore: invalid_use_of_internal_member - ..automatedTestMode = true + final options = defaultTestOptions() + ..platformChecker = getPlatformChecker(platform: mockPlatform) ..methodChannel = channel; sut = createBinding(options); }); diff --git a/flutter/test/span_frame_metrics_collector_test.dart b/flutter/test/span_frame_metrics_collector_test.dart index 70c3348070..41cb56b6d5 100644 --- a/flutter/test/span_frame_metrics_collector_test.dart +++ b/flutter/test/span_frame_metrics_collector_test.dart @@ -262,7 +262,7 @@ void main() { } class Fixture { - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final hub = Hub(options); final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); final mockSentryNative = MockSentryNativeBinding(); diff --git a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart index b0288729b2..cdb27f9275 100644 --- a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart +++ b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart @@ -524,7 +524,7 @@ Future tapMe( } class Fixture { - final _options = SentryFlutterOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); final _transport = MockTransport(); late Hub hub; diff --git a/flutter/test/view_hierarchy/sentry_tree_walker_test.dart b/flutter/test/view_hierarchy/sentry_tree_walker_test.dart index 9fd41fc522..26a7c41a0a 100644 --- a/flutter/test/view_hierarchy/sentry_tree_walker_test.dart +++ b/flutter/test/view_hierarchy/sentry_tree_walker_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/view_hierarchy/sentry_tree_walker.dart'; +import '../mocks.dart'; + void main() { group('TreeWalker', () { late WidgetsBinding instance; @@ -17,7 +19,7 @@ void main() { await tester.pumpWidget(MyApp()); final sentryViewHierarchy = - walkWidgetTree(instance, SentryFlutterOptions()); + walkWidgetTree(instance, defaultTestOptions()); expect(sentryViewHierarchy!.renderingSystem, 'flutter'); }); @@ -148,7 +150,7 @@ void main() { SentryViewHierarchyElement _getFirstSentryViewHierarchy( WidgetsBinding instance) { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); final sentryViewHierarchy = walkWidgetTree(instance, options); return sentryViewHierarchy!.windows.first; diff --git a/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart b/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart index 98487ab3a2..9ba8a694ff 100644 --- a/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart +++ b/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart @@ -4,9 +4,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/binding_wrapper.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_event_processor.dart'; +import '../mocks.dart'; + void main() { group(SentryViewHierarchyEventProcessor, () { late Fixture fixture; @@ -124,7 +125,7 @@ class TestBindingWrapper implements BindingWrapper { class Fixture { SentryViewHierarchyEventProcessor getSut(WidgetsBinding instance, {bool reportViewHierarchyIdentifiers = true}) { - final options = SentryFlutterOptions() + final options = defaultTestOptions() ..bindingUtils = TestBindingWrapper(instance) ..reportViewHierarchyIdentifiers = reportViewHierarchyIdentifiers; return SentryViewHierarchyEventProcessor(options); diff --git a/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart b/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart index bef4050c6e..c57fff8b5e 100644 --- a/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart +++ b/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart @@ -2,10 +2,10 @@ library flutter_test; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_event_processor.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -74,7 +74,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); SentryViewHierarchyIntegration getSut({bool attachViewHierarchy = true}) { options.attachViewHierarchy = attachViewHierarchy; diff --git a/flutter/test/widgets_binding_observer_test.dart b/flutter/test/widgets_binding_observer_test.dart index 86973ba91c..ce44577db9 100644 --- a/flutter/test/widgets_binding_observer_test.dart +++ b/flutter/test/widgets_binding_observer_test.dart @@ -17,11 +17,11 @@ void main() { setUp(() { TestWidgetsFlutterBinding.ensureInitialized(); - flutterTrackingEnabledOptions = SentryFlutterOptions() + flutterTrackingEnabledOptions = defaultTestOptions() ..bindingUtils = TestBindingWrapper(); flutterTrackingEnabledOptions.useFlutterBreadcrumbTracking(); - flutterTrackingDisabledOptions = SentryFlutterOptions() + flutterTrackingDisabledOptions = defaultTestOptions() ..bindingUtils = TestBindingWrapper(); flutterTrackingDisabledOptions.useNativeBreadcrumbTracking(); }); diff --git a/hive/test/sentry_box_base_test.dart b/hive/test/sentry_box_base_test.dart index 3821b8b341..e46564a3f3 100644 --- a/hive/test/sentry_box_base_test.dart +++ b/hive/test/sentry_box_base_test.dart @@ -12,6 +12,7 @@ import 'package:sentry/src/sentry_tracer.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -525,7 +526,7 @@ void main() { class Fixture { late final Box box; late final mockBox = MockBox(); - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/sentry_box_collection_test.dart b/hive/test/sentry_box_collection_test.dart index f13b95e1c8..3f730be3c1 100644 --- a/hive/test/sentry_box_collection_test.dart +++ b/hive/test/sentry_box_collection_test.dart @@ -15,6 +15,8 @@ import 'person.dart'; import 'package:hive/src/box_collection/box_collection_stub.dart' as stub; +import 'utils.dart'; + void main() { void verifySpan(String description, SentrySpan? span) { expect(span?.context.operation, SentryHiveImpl.dbOp); @@ -355,7 +357,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/sentry_hive_impl_test.dart b/hive/test/sentry_hive_impl_test.dart index 521415d1ed..a478c9f24a 100644 --- a/hive/test/sentry_hive_impl_test.dart +++ b/hive/test/sentry_hive_impl_test.dart @@ -14,6 +14,7 @@ import 'package:test/test.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan( @@ -583,7 +584,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); late final mockHive = MockHiveInterface(); final hub = MockHub(); static final dbName = 'people-hive-impl'; diff --git a/hive/test/sentry_lazy_box_test.dart b/hive/test/sentry_lazy_box_test.dart index 291dc3fc20..72282ada42 100644 --- a/hive/test/sentry_lazy_box_test.dart +++ b/hive/test/sentry_lazy_box_test.dart @@ -12,6 +12,7 @@ import 'package:test/test.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -247,7 +248,7 @@ void main() { class Fixture { late final LazyBox box; late final mockBox = MockLazyBox(); - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/utils.dart b/hive/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/hive/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/isar/test/sentry_isar_collection_test.dart b/isar/test/sentry_isar_collection_test.dart index de55ac5989..5cf06586ea 100644 --- a/isar/test/sentry_isar_collection_test.dart +++ b/isar/test/sentry_isar_collection_test.dart @@ -12,6 +12,7 @@ import 'package:sentry/src/sentry_tracer.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan( @@ -876,7 +877,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final isarCollection = MockIsarCollection(); diff --git a/isar/test/sentry_isar_test.dart b/isar/test/sentry_isar_test.dart index 222226fa53..00bafb2164 100644 --- a/isar/test/sentry_isar_test.dart +++ b/isar/test/sentry_isar_test.dart @@ -13,6 +13,7 @@ import 'package:sentry_isar/src/version.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -416,7 +417,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final isar = MockIsar(); diff --git a/isar/test/utils.dart b/isar/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/isar/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/logging/test/logging_integration_test.dart b/logging/test/logging_integration_test.dart index 5ddb50cf3e..c5e78657a5 100644 --- a/logging/test/logging_integration_test.dart +++ b/logging/test/logging_integration_test.dart @@ -203,7 +203,7 @@ void main() { } class Fixture { - SentryOptions options = SentryOptions(dsn: fakeDsn); + SentryOptions options = defaultTestOptions(); MockHub hub = MockHub(); LoggingIntegration createSut({ diff --git a/logging/test/mock_hub.dart b/logging/test/mock_hub.dart index 3dcb1d4fc8..ec3d8b2af9 100644 --- a/logging/test/mock_hub.dart +++ b/logging/test/mock_hub.dart @@ -6,10 +6,15 @@ import 'no_such_method_provider.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + class MockHub with NoSuchMethodProvider implements Hub { final List breadcrumbs = []; final List events = []; - final _options = SentryOptions(dsn: 'fixture-dsn'); + final _options = defaultTestOptions(); @override @internal diff --git a/sqflite/test/sentry_batch_test.dart b/sqflite/test/sentry_batch_test.dart index 4a5062f2a2..50dc469ab3 100644 --- a/sqflite/test/sentry_batch_test.dart +++ b/sqflite/test/sentry_batch_test.dart @@ -668,7 +668,7 @@ SELECT * FROM Product'''; class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); final batch = MockBatch(); diff --git a/sqflite/test/sentry_database_test.dart b/sqflite/test/sentry_database_test.dart index 93b258b20f..b97f97784e 100644 --- a/sqflite/test/sentry_database_test.dart +++ b/sqflite/test/sentry_database_test.dart @@ -1234,7 +1234,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); final database = MockDatabase(); diff --git a/sqflite/test/sentry_sqflite_database_factory_dart_test.dart b/sqflite/test/sentry_sqflite_database_factory_dart_test.dart index 061660884f..38bc23d404 100644 --- a/sqflite/test/sentry_sqflite_database_factory_dart_test.dart +++ b/sqflite/test/sentry_sqflite_database_factory_dart_test.dart @@ -95,7 +95,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); late final scope = Scope(options); diff --git a/sqflite/test/sentry_sqflite_test.dart b/sqflite/test/sentry_sqflite_test.dart index 41aa3277b9..f54cfda980 100644 --- a/sqflite/test/sentry_sqflite_test.dart +++ b/sqflite/test/sentry_sqflite_test.dart @@ -121,7 +121,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); late final scope = Scope(options); diff --git a/sqflite/test/utils.dart b/sqflite/test/utils.dart index 5dbeee585a..7fb87861f0 100644 --- a/sqflite/test/utils.dart +++ b/sqflite/test/utils.dart @@ -1 +1,8 @@ +import 'package:sentry/sentry.dart'; + final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +}