Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 12, 2024
1 parent 5cb2338 commit 2f093db
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions flutter/lib/src/integrations/native_sdk_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class NativeSdkIntegration implements Integration<SentryFlutterOptions> {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options?.automatedTestMode ?? false) {
rethrow;
}
}
}

Expand All @@ -44,6 +48,10 @@ class NativeSdkIntegration implements Integration<SentryFlutterOptions> {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options?.automatedTestMode ?? false) {
rethrow;
}
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions flutter/test/integrations/load_image_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {

setUp(() async {
fixture = IntegrationTestFixture(LoadImageListIntegration.new);
when(fixture.binding.loadDebugImages())
when(fixture.binding.loadDebugImages(any))
.thenAnswer((_) async => imageList);
await fixture.registerIntegration();
});
Expand All @@ -44,14 +44,14 @@ void main() {
await fixture.hub.captureException(StateError('error'),
stackTrace: StackTrace.current);

verifyNever(fixture.binding.loadDebugImages());
verifyNever(fixture.binding.loadDebugImages(any));
});

test('Native layer is not called if the event has no stack traces',
() async {
await fixture.hub.captureException(StateError('error'));

verifyNever(fixture.binding.loadDebugImages());
verifyNever(fixture.binding.loadDebugImages(any));
});

test('Native layer is called because stack traces are not symbolicated',
Expand All @@ -67,7 +67,7 @@ void main() {
#01 abs 000000723d637527 virt 00000000001f0527 _kDartIsolateSnapshotInstructions+0x1e5527
''');

verify(fixture.binding.loadDebugImages()).called(1);
verify(fixture.binding.loadDebugImages(any)).called(1);
});

test('Event processor adds image list to the event', () async {
Expand Down Expand Up @@ -100,7 +100,7 @@ void main() {
expect(fixture.options.eventProcessors.length, 1);

await fixture.hub.captureMessage('error');
verifyNever(fixture.binding.loadDebugImages());
verifyNever(fixture.binding.loadDebugImages(any));
});
});
}
Expand All @@ -110,4 +110,3 @@ SentryEvent _getEvent() {
final st = SentryStackTrace(frames: [frame]);
return SentryEvent(threads: [SentryThread(stacktrace: st)]);
}

8 changes: 8 additions & 0 deletions flutter/test/integrations/native_sdk_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void main() {

setUp(() {
fixture = IntegrationTestFixture(NativeSdkIntegration.new);
when(fixture.binding.init(any)).thenReturn(() {});
when(fixture.binding.close()).thenReturn(() {});
});

test('adds integration', () async {
Expand All @@ -25,6 +27,9 @@ void main() {
});

test('do not throw', () async {
// ignore: invalid_use_of_internal_member
fixture.options.automatedTestMode = false;

fixture.sut = NativeSdkIntegration(_ThrowingMockSentryNative());
await fixture.registerIntegration();
expect(fixture.options.sdk.integrations.contains('nativeSdkIntegration'),
Expand All @@ -51,6 +56,9 @@ void main() {
});

test(' is not added in case of an exception', () async {
// ignore: invalid_use_of_internal_member
fixture.options.automatedTestMode = false;

fixture.sut = NativeSdkIntegration(_ThrowingMockSentryNative());
await fixture.registerIntegration();
expect(fixture.options.sdk.integrations, <String>[]);
Expand Down
10 changes: 10 additions & 0 deletions flutter/test/native_scope_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,66 @@ void main() {
});

test('addBreadcrumbCalls', () async {
when(mock.addBreadcrumb(any)).thenReturn(() {});
final breadcrumb = Breadcrumb();
await sut.addBreadcrumb(breadcrumb);

expect(verify(mock.addBreadcrumb(captureAny)).captured.single, breadcrumb);
});

test('clearBreadcrumbsCalls', () async {
when(mock.clearBreadcrumbs()).thenReturn(() {});
await sut.clearBreadcrumbs();

verify(mock.clearBreadcrumbs()).called(1);
});

test('removeContextsCalls', () async {
when(mock.removeContexts(any)).thenReturn(() {});
await sut.removeContexts('fixture-key');

expect(
verify(mock.removeContexts(captureAny)).captured.single, 'fixture-key');
});

test('removeExtraCalls', () async {
when(mock.removeExtra(any)).thenReturn(() {});
await sut.removeExtra('fixture-key');

expect(verify(mock.removeExtra(captureAny)).captured.single, 'fixture-key');
});

test('removeTagCalls', () async {
when(mock.removeTag(any)).thenReturn(() {});
await sut.removeTag('fixture-key');

expect(verify(mock.removeTag(captureAny)).captured.single, 'fixture-key');
});

test('setContextsCalls', () async {
when(mock.setContexts(any, any)).thenReturn(() {});
await sut.setContexts('fixture-key', 'fixture-value');

verify(mock.setContexts('fixture-key', 'fixture-value')).called(1);
});

test('setExtraCalls', () async {
when(mock.setExtra(any, any)).thenReturn(() {});
await sut.setExtra('fixture-key', 'fixture-value');

verify(mock.setExtra('fixture-key', 'fixture-value')).called(1);
});

test('setTagCalls', () async {
when(mock.setTag(any, any)).thenReturn(() {});
await sut.setTag('fixture-key', 'fixture-value');

verify(mock.setTag('fixture-key', 'fixture-value')).called(1);
});

test('setUserCalls', () async {
when(mock.setUser(any)).thenReturn(() {});

final user = SentryUser(id: 'foo bar');
await sut.setUser(user);

Expand Down
2 changes: 2 additions & 0 deletions flutter/test/profiling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void main() {
});

test('dispose() calls native discard() exactly once', () async {
when(mock.discardProfiler(any)).thenReturn(() {});

sut.dispose();
sut.dispose(); // Additional calls must not have an effect.

Expand Down
14 changes: 9 additions & 5 deletions flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ void main() {
);

testScopeObserver(
options: sentryFlutterOptions!,
expectedHasNativeScopeObserver: true);
options: sentryFlutterOptions!, expectedHasNativeScopeObserver: true);

testConfiguration(
integrations: integrations,
Expand Down Expand Up @@ -630,7 +629,6 @@ void main() {
test(
'enablePureDartSymbolication is set to false during SentryFlutter init',
() async {
SentryFlutter.native = MockSentryNativeBinding();
await SentryFlutter.init(
(options) {
options.dsn = fakeDsn;
Expand All @@ -650,7 +648,7 @@ void main() {
});

test('resumeAppHangTracking calls native method when available', () async {
SentryFlutter.native = MockSentryNativeBinding();
SentryFlutter.native = mockNativeBinding();
when(SentryFlutter.native?.resumeAppHangTracking())
.thenAnswer((_) => Future.value());

Expand All @@ -669,7 +667,7 @@ void main() {
});

test('pauseAppHangTracking calls native method when available', () async {
SentryFlutter.native = MockSentryNativeBinding();
SentryFlutter.native = mockNativeBinding();
when(SentryFlutter.native?.pauseAppHangTracking())
.thenAnswer((_) => Future.value());

Expand Down Expand Up @@ -734,6 +732,12 @@ void main() {
});
}

MockSentryNativeBinding mockNativeBinding() {
final result = MockSentryNativeBinding();
when(result.supportsLoadContexts).thenReturn(true);
return result;
}

void appRunner() {}

void loadTestPackage() {
Expand Down

0 comments on commit 2f093db

Please sign in to comment.