-
-
Notifications
You must be signed in to change notification settings - Fork 258
Add tests for the Android and iOS plugin #1587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
8cb2613
57a189e
557867b
0e644ed
286e8f3
ddc9041
7d2c460
d905ab7
686e7d6
787dfac
a590378
c357792
a2f07a3
3cc4682
337e279
2b774a1
a3cdb7a
dbb1454
cd604d4
fb9c99d
c858af8
7fcb9e9
6dc9e6c
a44bfcc
424a77b
d2434bf
edf9110
8d4afdb
1bff064
179656e
e8856a1
83231b6
2c1495a
acdd4a4
a505327
b2cdeeb
6e5aba2
ef5516a
0fd5be0
89b82fb
170763a
c2d8736
671d550
fcecded
4905b17
1a84ab4
62aa008
430038b
da19bc2
2c11a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,18 @@ jobs: | |
profile: Nexus 6 | ||
script: flutter test integration_test/integration_test.dart --verbose | ||
|
||
- name: launch android emulator & run android native test | ||
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #[email protected] | ||
with: | ||
working-directory: ./flutter/example/android | ||
api-level: 21 | ||
force-avd-creation: false | ||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
disable-animations: true | ||
arch: x86_64 | ||
profile: Nexus 6 | ||
script: ./gradlew testDebugUnitTest | ||
|
||
test-ios: | ||
runs-on: macos-13 | ||
timeout-minutes: 30 | ||
|
@@ -113,5 +125,9 @@ jobs: | |
simulator_id=$(xcrun simctl create sentryPhone com.apple.CoreSimulator.SimDeviceType.iPhone-14 com.apple.CoreSimulator.SimRuntime.iOS-16-2) | ||
xcrun simctl boot ${simulator_id} | ||
|
||
- name: run ios integration test | ||
run: flutter test integration_test/integration_test.dart --verbose | ||
# - name: run ios integration test | ||
# run: flutter test integration_test/integration_test.dart --verbose | ||
|
||
- name: run native test | ||
working-directory: ./flutter/example/ios | ||
run: xcodebuild test -workspace Runner.xcworkspace -scheme Runner -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 14' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.sentry.flutter | ||
|
||
import io.sentry.SentryLevel | ||
import io.sentry.android.core.BuildConfig | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import io.sentry.protocol.SdkVersion | ||
import java.util.Locale | ||
|
||
class SentryFlutter( | ||
private val androidSdk: String, | ||
private val nativeSdk: String | ||
) { | ||
|
||
var autoPerformanceTracingEnabled = false | ||
|
||
fun updateOptions(options: SentryAndroidOptions, data: Map<String, Any>) { | ||
data.getIfNotNull<String>("dsn") { | ||
options.dsn = it | ||
} | ||
data.getIfNotNull<Boolean>("debug") { options.isDebug = it } | ||
data.getIfNotNull<String>("environment") { options.environment = it } | ||
data.getIfNotNull<String>("release") { options.release = it } | ||
data.getIfNotNull<String>("dist") { options.dist = it } | ||
data.getIfNotNull<Boolean>("enableAutoSessionTracking") { options.isEnableAutoSessionTracking = it } | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data.getIfNotNull<Long>("autoSessionTrackingIntervalMillis") { options.sessionTrackingIntervalMillis = it } | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data.getIfNotNull<Long>("anrTimeoutIntervalMillis") { options.anrTimeoutIntervalMillis = it } | ||
data.getIfNotNull<Boolean>("attachThreads") { options.isAttachThreads = it } | ||
data.getIfNotNull<Boolean>("attachStacktrace") { options.isAttachStacktrace = it } | ||
data.getIfNotNull<Boolean>("enableAutoNativeBreadcrumbs") { | ||
options.isEnableActivityLifecycleBreadcrumbs = it | ||
options.isEnableAppLifecycleBreadcrumbs = it | ||
options.isEnableSystemEventBreadcrumbs = it | ||
options.isEnableAppComponentBreadcrumbs = it | ||
options.isEnableUserInteractionBreadcrumbs = it | ||
} | ||
data.getIfNotNull<Int>("maxBreadcrumbs") { options.maxBreadcrumbs = it } | ||
data.getIfNotNull<Int>("maxCacheItems") { options.maxCacheItems = it } | ||
data.getIfNotNull<String>("diagnosticLevel") { | ||
if (options.isDebug) { | ||
val sentryLevel = SentryLevel.valueOf(it.toUpperCase(Locale.ROOT)) | ||
options.setDiagnosticLevel(sentryLevel) | ||
} | ||
} | ||
data.getIfNotNull<Boolean>("anrEnabled") { options.isAnrEnabled = it } | ||
data.getIfNotNull<Boolean>("sendDefaultPii") { options.isSendDefaultPii = it } | ||
data.getIfNotNull<Boolean>("enableNdkScopeSync") { options.isEnableScopeSync = it } | ||
data.getIfNotNull<String>("proguardUuid") { options.proguardUuid = it } | ||
|
||
val nativeCrashHandling = (data["enableNativeCrashHandling"] as? Boolean) ?: true | ||
// nativeCrashHandling has priority over anrEnabled | ||
if (!nativeCrashHandling) { | ||
options.isEnableUncaughtExceptionHandler = false | ||
options.isAnrEnabled = false | ||
// if split symbols are enabled, we need Ndk integration so we can't really offer the option | ||
// to turn it off | ||
// options.isEnableNdk = false | ||
} | ||
|
||
data.getIfNotNull<Boolean>("enableAutoPerformanceTracing") { enableAutoPerformanceTracing -> | ||
if (enableAutoPerformanceTracing) { | ||
autoPerformanceTracingEnabled = true | ||
} | ||
} | ||
|
||
data.getIfNotNull<Boolean>("sendClientReports") { options.isSendClientReports = it } | ||
|
||
data.getIfNotNull<Long>("maxAttachmentSize") { options.maxAttachmentSize = it } | ||
|
||
var sdkVersion = options.sdkVersion | ||
if (sdkVersion == null) { | ||
sdkVersion = SdkVersion(androidSdk, BuildConfig.VERSION_NAME) | ||
} else { | ||
sdkVersion.name = androidSdk | ||
} | ||
|
||
options.sdkVersion = sdkVersion | ||
options.sentryClientName = "$androidSdk/${BuildConfig.VERSION_NAME}" | ||
options.nativeSdkName = nativeSdk | ||
|
||
data.getIfNotNull<Int>("connectionTimeoutMillis") { options.connectionTimeoutMillis = it } | ||
data.getIfNotNull<Int>("readTimeoutMillis") { options.readTimeoutMillis = it } | ||
} | ||
} | ||
|
||
// Call the `completion` closure if cast to map value with `key` and type `T` is successful. | ||
@Suppress("UNCHECKED_CAST") | ||
private fun <T> Map<String, Any>.getIfNotNull(key: String, callback: (T) -> Unit) { | ||
(get(key) as? T)?.let { | ||
callback(it) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package io.sentry.flutter | ||
|
||
import io.sentry.SentryLevel | ||
import io.sentry.android.core.BuildConfig | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class SentryFlutterTest { | ||
|
||
private lateinit var fixture: Fixture | ||
|
||
@Before | ||
fun before() { | ||
fixture = Fixture() | ||
} | ||
|
||
@Test | ||
fun initNativeSkd() { | ||
// Given | ||
val sut = fixture.getSut() | ||
|
||
// When | ||
sut.updateOptions(fixture.options, mapOf( | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"dsn" to "fixture-dsn", | ||
"debug" to true, | ||
"environment" to "fixture-environment", | ||
"release" to "fixture-release", | ||
"dist" to "fixture-dist", | ||
"enableAutoSessionTracking" to false, | ||
"autoSessionTrackingIntervalMillis" to 9001L, | ||
"anrTimeoutIntervalMillis" to 9002L, | ||
"attachThreads" to true, | ||
"attachStacktrace" to false, | ||
"enableAutoNativeBreadcrumbs" to false, | ||
"maxBreadcrumbs" to 9003, | ||
"maxCacheItems" to 9004, | ||
"anrEnabled" to false, | ||
"sendDefaultPii" to true, | ||
"enableNdkScopeSync" to false, | ||
"proguardUuid" to "fixture-proguardUuid", | ||
"enableNativeCrashHandling" to false, | ||
"sendClientReports" to false, | ||
"maxAttachmentSize" to 9005L, | ||
"enableAutoPerformanceTracing" to true, | ||
"connectionTimeoutMillis" to 9006, | ||
"readTimeoutMillis" to 9007, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-call-site reported by reviewdog 🐶 |
||
)) | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Then | ||
assertEquals("fixture-dsn", fixture.options.dsn) | ||
assertEquals(true, fixture.options.isDebug) | ||
assertEquals("fixture-environment", fixture.options.environment) | ||
assertEquals("fixture-release", fixture.options.release) | ||
assertEquals("fixture-dist", fixture.options.dist) | ||
assertEquals(false, fixture.options.isEnableAutoSessionTracking) | ||
assertEquals(9001L, fixture.options.sessionTrackingIntervalMillis) | ||
assertEquals(9002L, fixture.options.anrTimeoutIntervalMillis) | ||
assertEquals(true, fixture.options.isAttachThreads) | ||
assertEquals(false, fixture.options.isAttachStacktrace) | ||
assertEquals(false, fixture.options.isEnableActivityLifecycleBreadcrumbs) | ||
assertEquals(false, fixture.options.isEnableAppLifecycleBreadcrumbs) | ||
assertEquals(false, fixture.options.isEnableSystemEventBreadcrumbs) | ||
assertEquals(false, fixture.options.isEnableAppComponentBreadcrumbs) | ||
assertEquals(false, fixture.options.isEnableUserInteractionBreadcrumbs) | ||
assertEquals(9003, fixture.options.maxBreadcrumbs) | ||
assertEquals(9004, fixture.options.maxCacheItems) | ||
assertEquals(false, fixture.options.isAnrEnabled) | ||
assertEquals(true, fixture.options.isSendDefaultPii) | ||
assertEquals(false, fixture.options.isEnableScopeSync) | ||
assertEquals("fixture-proguardUuid", fixture.options.proguardUuid) | ||
assertEquals(false, fixture.options.isSendClientReports) | ||
assertEquals(9005L, fixture.options.maxAttachmentSize) | ||
|
||
assertEquals("sentry.java.android.flutter", fixture.options.sdkVersion?.name) | ||
assertEquals(BuildConfig.VERSION_NAME, fixture.options.sdkVersion?.version) | ||
assertEquals("sentry.java.android.flutter/${BuildConfig.VERSION_NAME}", fixture.options.sentryClientName) | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:argument-list-wrapping reported by reviewdog 🐶
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertEquals("fixture-nativeSdk", fixture.options.nativeSdkName) | ||
|
||
assertEquals(true, sut.autoPerformanceTracingEnabled) | ||
|
||
assertEquals(9006, fixture.options.connectionTimeoutMillis) | ||
assertEquals(9007, fixture.options.readTimeoutMillis) | ||
} | ||
|
||
@Test | ||
fun initNativeSdkDiagnosticLevel() { | ||
// Given | ||
val sut = fixture.getSut() | ||
fixture.options.isDebug = true | ||
|
||
// When | ||
sut.updateOptions(fixture.options, mapOf( | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"diagnosticLevel" to "warning", | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)) | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Then | ||
assertEquals(SentryLevel.WARNING, fixture.options.diagnosticLevel) | ||
} | ||
|
||
@Test | ||
fun initNativeSdkEnableNativeCrashHandling() { | ||
// Given | ||
val sut = fixture.getSut() | ||
|
||
// When | ||
sut.updateOptions(fixture.options, mapOf( | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"enableNativeCrashHandling" to false, | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)) | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Then | ||
assertEquals(false, fixture.options.isEnableUncaughtExceptionHandler) | ||
assertEquals(false, fixture.options.isAnrEnabled) | ||
} | ||
} | ||
|
||
class Fixture { | ||
|
||
var options = SentryAndroidOptions() | ||
|
||
fun getSut(): SentryFlutter { | ||
return SentryFlutter( | ||
androidSdk = "sentry.java.android.flutter", | ||
nativeSdk = "fixture-nativeSdk", | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.