@@ -5,7 +5,9 @@ import androidx.test.core.app.launchActivity
55import androidx.test.ext.junit.runners.AndroidJUnit4
66import io.sentry.ProfilingTraceData
77import io.sentry.Sentry
8+ import io.sentry.SentryIntegrationPackageStorage
89import io.sentry.android.core.AndroidLogger
10+ import io.sentry.android.core.CurrentActivityHolder
911import io.sentry.android.core.SentryAndroidOptions
1012import io.sentry.assertEnvelopeTransaction
1113import io.sentry.protocol.SentryTransaction
@@ -15,6 +17,7 @@ import org.junit.runner.RunWith
1517import shark.AndroidReferenceMatchers
1618import shark.IgnoredReferenceMatcher
1719import shark.ReferencePattern
20+ import java.util.concurrent.CountDownLatch
1821import kotlin.test.Test
1922import kotlin.test.assertEquals
2023import kotlin.test.assertTrue
@@ -215,4 +218,65 @@ class SdkInitTests : BaseUiTest() {
215218
216219 LeakAssertions .assertNoLeaks()
217220 }
221+
222+ @Test
223+ fun foregroundInitInstallsDefaultIntegrations () {
224+ val activityScenario = launchActivity<ComposeActivity >()
225+ activityScenario.moveToState(Lifecycle .State .RESUMED )
226+ activityScenario.onActivity { activity ->
227+ // Our SentryInitProvider does not run in this test
228+ // so we need to set the current activity manually
229+ CurrentActivityHolder .getInstance().setActivity(activity)
230+ initSentry(false ) { options: SentryAndroidOptions ->
231+ options.tracesSampleRate = 1.0
232+ options.profilesSampleRate = 1.0
233+ }
234+ }
235+ activityScenario.moveToState(Lifecycle .State .DESTROYED )
236+ assertDefaultIntegrations()
237+ }
238+
239+ @Test
240+ fun backgroundInitInstallsDefaultIntegrations () {
241+ val initLatch = CountDownLatch (1 )
242+
243+ val activityScenario = launchActivity<ComposeActivity >()
244+ activityScenario.moveToState(Lifecycle .State .RESUMED )
245+ activityScenario.onActivity { activity ->
246+ // Our SentryInitProvider does not run in this test
247+ // so we need to set the current activity manually
248+ CurrentActivityHolder .getInstance().setActivity(activity)
249+ Thread {
250+ initSentry(false ) { options: SentryAndroidOptions ->
251+ options.tracesSampleRate = 1.0
252+ options.profilesSampleRate = 1.0
253+ }
254+ initLatch.countDown()
255+ }.start()
256+ }
257+ initLatch.await()
258+
259+ activityScenario.moveToState(Lifecycle .State .DESTROYED )
260+
261+ assertDefaultIntegrations()
262+ }
263+
264+ private fun assertDefaultIntegrations () {
265+ for (integration in listOf (
266+ " UncaughtExceptionHandler" ,
267+ " ShutdownHook" ,
268+ " SendCachedEnvelope" ,
269+ " Ndk" ,
270+ " AppLifecycle" ,
271+ " EnvelopeFileObserver" ,
272+ " AnrV2" ,
273+ " ActivityLifecycle" ,
274+ " ActivityBreadcrumbs" ,
275+ " UserInteraction" ,
276+ " AppComponentsBreadcrumbs" ,
277+ " NetworkBreadcrumbs"
278+ )) {
279+ assertTrue(SentryIntegrationPackageStorage .getInstance().integrations.contains(integration), " Integration $integration was expected, but was not registered" )
280+ }
281+ }
218282}
0 commit comments