https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

galex

06/25/2019, 5:38 AM
Hello, does someone have an example of a Multiplatform project that runs common unit tests on its Android library target? Since
1.3.40
to just compile I had to add the following in the root level dependencies block:
Copy code
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
Running the gradle task
build
, which runs the tasks
testDebugUnitTest
fails:
Copy code
> Task :testDebugUnitTest FAILED

com.mu51k.core.util.EmailUtilsTests > emailsAreInvalid FAILED
    java.lang.NullPointerException at EmailUtilsTests.kt:20

com.mu51k.core.util.EmailUtilsTests > emailsAreValid FAILED
    java.lang.NullPointerException at EmailUtilsTests.kt:12

2 tests completed, 2 failed
The NPE seems weird, as the code looks like that:
Copy code
assertTrue { "<mailto:glfala@fefr.com|glfala@fefr.com>".emailValid() }
And
emailValid()
on Android is the following:
Copy code
actual fun String.emailValid(): Boolean = Patterns.EMAIL_ADDRESS.matcher(this).matches()
Any idea?
g

gildor

06/25/2019, 5:40 AM
Looks that 2 tests are failed, what is stacktrace of failed tests?
g

galex

06/25/2019, 5:43 AM
@gildor Added more info
g

gildor

06/25/2019, 5:46 AM
Because Patterns.EMAIL_ADDRESS is Android Framework field
and it’s just not available in unit tests, it’s equal
null
in android.jar that used for unit tests (like any other Android Framework method or non-constant field)
Just use own common regex for this, also it will make behaviour on different platform more similar
g

galex

06/25/2019, 6:04 AM
Ah right, thank you
3 Views