|
| 1 | +import 'package:flutter/widgets.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:integration_test/integration_test.dart'; |
| 4 | +import 'package:sentry_flutter/sentry_flutter.dart'; |
| 5 | +import 'package:sentry_flutter_example/main.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 9 | + binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; |
| 10 | + |
| 11 | + Future<void> setupSentryAndApp(WidgetTester tester) async { |
| 12 | + await setupSentry(() async { |
| 13 | + await tester.pumpWidget(SentryScreenshotWidget( |
| 14 | + child: DefaultAssetBundle( |
| 15 | + bundle: SentryAssetBundle(enableStructuredDataTracing: true), |
| 16 | + child: MyApp(), |
| 17 | + ))); |
| 18 | + await tester.pumpAndSettle(); |
| 19 | + }); |
| 20 | + } |
| 21 | + |
| 22 | + // Tests |
| 23 | + |
| 24 | + testWidgets('setup sentry and render app', (tester) async { |
| 25 | + await setupSentryAndApp(tester); |
| 26 | + |
| 27 | + // Find any UI element and verify it is present. |
| 28 | + expect(find.text('Open another Scaffold'), findsOneWidget); |
| 29 | + }); |
| 30 | + |
| 31 | + testWidgets('setup sentry and capture event', (tester) async { |
| 32 | + await setupSentryAndApp(tester); |
| 33 | + |
| 34 | + final event = SentryEvent(); |
| 35 | + final sentryId = await Sentry.captureEvent(event); |
| 36 | + |
| 37 | + expect(sentryId != SentryId.empty(), true); |
| 38 | + }); |
| 39 | + |
| 40 | + testWidgets('setup sentry and capture exception', (tester) async { |
| 41 | + await setupSentryAndApp(tester); |
| 42 | + |
| 43 | + try { |
| 44 | + throw SentryException( |
| 45 | + type: 'StarError', value: 'I have a bad feeling about this...'); |
| 46 | + } catch (exception, stacktrace) { |
| 47 | + final sentryId = |
| 48 | + await Sentry.captureException(exception, stackTrace: stacktrace); |
| 49 | + |
| 50 | + expect(sentryId != SentryId.empty(), true); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + testWidgets('setup sentry and capture message', (tester) async { |
| 55 | + await setupSentryAndApp(tester); |
| 56 | + |
| 57 | + final sentryId = await Sentry.captureMessage('hello world!'); |
| 58 | + |
| 59 | + expect(sentryId != SentryId.empty(), true); |
| 60 | + }); |
| 61 | + |
| 62 | + testWidgets('setup sentry and capture user feedback', (tester) async { |
| 63 | + await setupSentryAndApp(tester); |
| 64 | + |
| 65 | + final feedback = SentryUserFeedback( |
| 66 | + eventId: SentryId.newId(), |
| 67 | + name: 'fixture-name', |
| 68 | + |
| 69 | + comments: 'fixture-comments'); |
| 70 | + await Sentry.captureUserFeedback(feedback); |
| 71 | + }); |
| 72 | + |
| 73 | + testWidgets('setup sentry and close', (tester) async { |
| 74 | + await setupSentryAndApp(tester); |
| 75 | + |
| 76 | + await Sentry.close(); |
| 77 | + }); |
| 78 | + |
| 79 | + testWidgets('setup sentry and add breadcrumb', (tester) async { |
| 80 | + await setupSentryAndApp(tester); |
| 81 | + |
| 82 | + final breadcrumb = Breadcrumb(message: 'fixture-message'); |
| 83 | + await Sentry.addBreadcrumb(breadcrumb); |
| 84 | + }); |
| 85 | + |
| 86 | + testWidgets('setup sentry and configure scope', (tester) async { |
| 87 | + await setupSentryAndApp(tester); |
| 88 | + |
| 89 | + await Sentry.configureScope((scope) async { |
| 90 | + await scope.setContexts('contexts-key', 'contexts-value'); |
| 91 | + await scope.removeContexts('contexts-key'); |
| 92 | + |
| 93 | + final user = SentryUser(id: 'fixture-id'); |
| 94 | + await scope.setUser(user); |
| 95 | + await scope.setUser(null); |
| 96 | + |
| 97 | + final breadcrumb = Breadcrumb(message: 'fixture-message'); |
| 98 | + await scope.addBreadcrumb(breadcrumb); |
| 99 | + await scope.clearBreadcrumbs(); |
| 100 | + |
| 101 | + await scope.setExtra('extra-key', 'extra-value'); |
| 102 | + await scope.removeExtra('extra-key'); |
| 103 | + |
| 104 | + await scope.setTag('tag-key', 'tag-value'); |
| 105 | + await scope.removeTag('tag-key'); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + testWidgets('setup sentry and start transaction', (tester) async { |
| 110 | + await setupSentryAndApp(tester); |
| 111 | + |
| 112 | + final transaction = Sentry.startTransaction('transaction', 'test'); |
| 113 | + await transaction.finish(); |
| 114 | + }); |
| 115 | + |
| 116 | + testWidgets('setup sentry and start transaction with context', |
| 117 | + (tester) async { |
| 118 | + await setupSentryAndApp(tester); |
| 119 | + |
| 120 | + final context = SentryTransactionContext('transaction', 'test'); |
| 121 | + final transaction = Sentry.startTransactionWithContext(context); |
| 122 | + await transaction.finish(); |
| 123 | + }); |
| 124 | +} |
0 commit comments