Skip to content

Commit 31d1657

Browse files
committed
Extend tests to ensure default integrations are registered
1 parent 7a07346 commit 31d1657

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

sentry-android-integration-tests/sentry-uitest-android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ android {
6161
isMinifyEnabled = true
6262
signingConfig = signingConfigs.getByName("debug")
6363
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
64+
testProguardFiles("proguard-rules.pro")
6465
}
6566
getByName("release") {
6667
isMinifyEnabled = true

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import androidx.test.core.app.launchActivity
55
import androidx.test.ext.junit.runners.AndroidJUnit4
66
import io.sentry.ProfilingTraceData
77
import io.sentry.Sentry
8+
import io.sentry.SentryIntegrationPackageStorage
89
import io.sentry.android.core.AndroidLogger
10+
import io.sentry.android.core.CurrentActivityHolder
911
import io.sentry.android.core.SentryAndroidOptions
1012
import io.sentry.assertEnvelopeTransaction
1113
import io.sentry.protocol.SentryTransaction
@@ -15,6 +17,7 @@ import org.junit.runner.RunWith
1517
import shark.AndroidReferenceMatchers
1618
import shark.IgnoredReferenceMatcher
1719
import shark.ReferencePattern
20+
import java.util.concurrent.CountDownLatch
1821
import kotlin.test.Test
1922
import kotlin.test.assertEquals
2023
import 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

Comments
 (0)