How to I get access to the android context in a ko...
# multiplatform
m
How to I get access to the android context in a kotlin multiplatform test? Specifically inside
androidTest
as it wouldn't make sense outside the android source set? I've tried searching for this but I could not find an example that I can understand/works
k
In my
androidTest
sourcset, I have a dependency on
androidx.test.ext:junit-ktx
, which gives you access to
ApplicationProvider
class
m
I tried this but I can't find the class. Can you show me a code example?
(I'm quite desperate to get this working 😅 )
k
You added a dependency in
androidTest
, right?
m
yeah, I did this
k
okay, so now, how does your test look like? Do you do
expect/actual
to run in common code?
m
I do, in androidTest I tried to type
ApplicationProvider
and it didn't pop up in auto complete
k
maybe it did not sync correctly? It’s imported from
androidx.test.core.app.ApplicationProvider
I use version 1.1.3, but I doubt that ApplicationProvider is removed from 1.1.4 (which you have)
m
intellij keeps unmarking my kotlin dirs as sources root/test root idk why (the blue and green folders) and autocomplete stopped working for me
but not that I marked them again it autocompletes, running the test now to see if it works
ran into this now
k
You need a complete android setup. I’ve used Touchlab’s document when I was creating tests for first time, I think it can come handy for you too https://touchlab.co/understanding-and-configuring-your-kmm-test-suite/
m
okay, I added a few things to my gradle file and now the test refuses to run 😕 all other tests run and show up in the output window of the ide, but the android one disappeared
this is the diff, first block is inside the top level
android {}
block and the second part is inside the top level
kotlin {}
block
215 Views