@@ -5,7 +5,10 @@ import androidx.test.core.app.launchActivity
5
5
import androidx.test.ext.junit.runners.AndroidJUnit4
6
6
import io.sentry.ProfilingTraceData
7
7
import io.sentry.Sentry
8
+ import io.sentry.SentryIntegrationPackageStorage
8
9
import io.sentry.android.core.AndroidLogger
10
+ import io.sentry.android.core.CurrentActivityHolder
11
+ import io.sentry.android.core.NdkIntegration
9
12
import io.sentry.android.core.SentryAndroidOptions
10
13
import io.sentry.assertEnvelopeTransaction
11
14
import io.sentry.protocol.SentryTransaction
@@ -15,6 +18,7 @@ import org.junit.runner.RunWith
15
18
import shark.AndroidReferenceMatchers
16
19
import shark.IgnoredReferenceMatcher
17
20
import shark.ReferencePattern
21
+ import java.util.concurrent.CountDownLatch
18
22
import kotlin.test.Test
19
23
import kotlin.test.assertEquals
20
24
import kotlin.test.assertTrue
@@ -215,4 +219,74 @@ class SdkInitTests : BaseUiTest() {
215
219
216
220
LeakAssertions .assertNoLeaks()
217
221
}
222
+
223
+ @Test
224
+ fun foregroundInitInstallsDefaultIntegrations () {
225
+ val activityScenario = launchActivity<ComposeActivity >()
226
+ activityScenario.moveToState(Lifecycle .State .RESUMED )
227
+ activityScenario.onActivity { activity ->
228
+ // Our SentryInitProvider does not run in this test
229
+ // so we need to set the current activity manually
230
+ CurrentActivityHolder .getInstance().setActivity(activity)
231
+ initSentry(false ) { options: SentryAndroidOptions ->
232
+ options.tracesSampleRate = 1.0
233
+ options.profilesSampleRate = 1.0
234
+ }
235
+ }
236
+ activityScenario.moveToState(Lifecycle .State .DESTROYED )
237
+ assertDefaultIntegrations()
238
+ }
239
+
240
+ @Test
241
+ fun backgroundInitInstallsDefaultIntegrations () {
242
+ val initLatch = CountDownLatch (1 )
243
+
244
+ val activityScenario = launchActivity<ComposeActivity >()
245
+ activityScenario.moveToState(Lifecycle .State .RESUMED )
246
+ activityScenario.onActivity { activity ->
247
+ // Our SentryInitProvider does not run in this test
248
+ // so we need to set the current activity manually
249
+ CurrentActivityHolder .getInstance().setActivity(activity)
250
+ Thread {
251
+ initSentry(false ) { options: SentryAndroidOptions ->
252
+ options.tracesSampleRate = 1.0
253
+ options.profilesSampleRate = 1.0
254
+ }
255
+ initLatch.countDown()
256
+ }.start()
257
+ }
258
+ initLatch.await()
259
+
260
+ activityScenario.moveToState(Lifecycle .State .DESTROYED )
261
+
262
+ assertDefaultIntegrations()
263
+ }
264
+
265
+ private fun assertDefaultIntegrations () {
266
+ val integrations = mutableListOf (
267
+ " UncaughtExceptionHandler" ,
268
+ " ShutdownHook" ,
269
+ " SendCachedEnvelope" ,
270
+ " AppLifecycle" ,
271
+ " EnvelopeFileObserver" ,
272
+ " AnrV2" ,
273
+ " ActivityLifecycle" ,
274
+ " ActivityBreadcrumbs" ,
275
+ " UserInteraction" ,
276
+ " AppComponentsBreadcrumbs" ,
277
+ " NetworkBreadcrumbs"
278
+ )
279
+
280
+ // NdkIntegration is not always available, so we check for its presence
281
+ try {
282
+ Class .forName(NdkIntegration .SENTRY_NDK_CLASS_NAME )
283
+ integrations.add(" Ndk" )
284
+ } catch (_: ClassNotFoundException ) {
285
+ // ignored, in case the app is build without NDK support
286
+ }
287
+
288
+ for (integration in integrations) {
289
+ assertTrue(SentryIntegrationPackageStorage .getInstance().integrations.contains(integration), " Integration $integration was expected, but was not registered" )
290
+ }
291
+ }
218
292
}
0 commit comments