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

ribesg

05/03/2019, 1:01 PM
Anyone got an example of Android & iOS testing in a multiplatform library and app(s)?
d

Dennis L

05/03/2019, 1:03 PM
There's tests in https://github.com/SimonSchubert/Newsout but I'm trying to figure out how they work too
r

ribesg

05/03/2019, 1:13 PM
I only have a single multiplatform module, I’m trying to get the Android tests to run. Your source should help running iOS tests I think
k

kpgalligan

05/03/2019, 1:19 PM
We’ve been refactoring https://github.com/touchlab/DroidconKotlin/ for tests. See https://github.com/touchlab/DroidconKotlin/blob/master/sessionize/lib/src/commonMain/kotlin/co/touchlab/sessionize/ServiceRegistry.kt. It takes a bunch of interfaces, which in test have some definitions, and in main, delegate to real versions. The actual “tests” are a work in progress, but being able to do manual dependency injection and test implementations is functional.
r

ribesg

05/03/2019, 1:23 PM
Woa I’m just at the step where I want to assert that
1 == 1
in a function and being able to run it
I’ve got two test functions with
@Test
in
commonTest
but
gradle test
does not see them. (
gradle test
should run the Android unit tests)
Hmm…
Code? Are they in a class?
r

ribesg

05/03/2019, 1:26 PM
I put a class around my tests but it still doesn’t work. I’ve got these dependencies:
Copy code
getByName("commonTest") {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
Copy code
getByName("androidTest") {
            dependencies {
                implementation(kotlin("test"))
                implementation(kotlin("test-testng"))
                implementation("org.testng:testng:6.13.1")
            }
        }
I’m replacing
testng
with
junit
Looks like it runs them but now I get a
NoClassDefFoundError
on something that is
internal
in the code module 😕
k

kpgalligan

05/03/2019, 1:30 PM
Don’t know about that
You should be able to. I don’t know why yours is not working. Would need to see actual code, but if this isn’t open source code, it would be much easier to maybe make a test project to verify and experiment.
m

mben

05/03/2019, 1:45 PM
Hello i have a question about testing i'm doing tdd and when i use a non existant class and do cmd + enter and put target destination in commonMain i have a warning no source roots configured and i dont know how to fixe it
ide freeze after that
r

ribesg

05/03/2019, 1:50 PM
I’m still switching from
junit
to
junit5
to
testng
and trying to find something that works
m

mben

05/03/2019, 1:54 PM
more precisely when i use non existant class in test and then cmd + enter -> create class -> Extract to separate file and put target destination : commonMain/folder i get dialogue with No Source Roots configured for module SharedCode_commonTest then ide freeze
k

kpgalligan

05/03/2019, 2:02 PM
I believe in the jvm, ‘testing’ will delegate to junit anyway.
r

russhwolf

05/03/2019, 4:44 PM
@ribesg Try using
gradle check
instead of
gradle test
. That's the command most of the default multiplatform gradle setups are built for.
👍 1
8 Views