hi there, I'm trying to run an UI test in shared/c...
# multiplatform
k
hi there, I'm trying to run an UI test in shared/commonTest and facing the following NPE. This tests works fine when I run it in androidInstrumentedTest. Any ideas?
Copy code
java.lang.NullPointerException: Cannot invoke "String.toLowerCase(java.util.Locale)" because "android.os.Build.FINGERPRINT" is null
	at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.runTest(ComposeUiTest.android.kt:314)
	at androidx.compose.ui.test.ComposeUiTest_androidKt.runAndroidComposeUiTest(ComposeUiTest.android.kt:114)
	at androidx.compose.ui.test.ComposeUiTest_androidKt.runComposeUiTest(ComposeUiTest.android.kt:61)
	at androidx.compose.ui.test.ComposeUiTest_androidKt.runComposeUiTest$default(ComposeUiTest.android.kt:60)
a
Android.os.Build.FINGERPRINT is android specific and its used in commonTest, that will not work
The commonTest should use only kotlin code and its agnostic of theplatform
k
thank you @Alexandru Caraus I was referring to the test example on https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-test.html#writing-and-running-tests-with-compose-multiplatform there is an implementation of a common test - so this won't work for android, do I understand it right?
a
It should work for android
The commonTest should test everything from common. And in common you should not reference anything android or ios, or any other platform. You would need to mock probably some expect/actual.
From the error you have its clear that the commonTest tries to run something android specific, and that should not be allowed.
Hope its clear.
a
Is this planned to be fixed? If yes is there any tracking bug id? This crashes even for common compose code when run using
allTest
(when ran for android environment)
Or should this be an issue on Google's side as this crash happens on
ComposeUiTest.android.kt
?
j
Also running in to this just running say
testDebugUnitTest
this is only test in
commonTest
so definitely nothing android related
Copy code
@Test
    fun myFirstTest() = runComposeUiTest {
        setContent {
            Text("hi")
        }

        onNodeWithText("hi").assertExists()
    }
running
desktopTest
works fine (using jvm target)
fwiw following seems to work to at least prevent the CMP UI tests (that are for example in
screen
folder in commonTest) from running as part of
testDebugUnitTest
test run....they still run when using
connectedAndroidTest
(cc @Marco Pierucci)
Copy code
testOptions {
        unitTests {
            all {
                it.exclude("**/screen/**")
            }
        }
    }
also can run for example
allTests
and that will run all tests on all platforms (but won't run the
screen
one when running for android (local) because of the
testOptions
filter mentioned above ) ....updated https://github.com/joreilly/ClimateTraceKMP/tree/cmp_tests branch with those changes
m
Excellent! We can agree on add all UI test in ui package or something and start adding tests then
Thanks!
1157 Views