I would like to write some tests for an operator w...
# coroutines
a
I would like to write some tests for an operator which filters button press events (see thread from yesterday). To get some inspiration for the right approach, I’ve been looking at some of the existing Kotlin Coroutine tests e.g.
kotlinx.coroutines/kotlinx-coroutines-core/common/test/TestBase.common.kt
. Is it possible to re-use
TestBase()
my own tests? I’ve tried
import kotlin.test.*
however this package is not found, despite having the following in my Android app `build.gradle`:
implementation ‘org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3’
I’ve also tried adding a
testImplementation
line with the same, but the above import still fails. Is re-using
TestBase()
etc. in my code not possible? Or is their a separate
testImplementation
entry I should add to my app
build.gradle
?
e
with the default Gradle setup, only the
main
sourceset is exposed, the
test
sourceset remains internal to that project. tl;dr no, you can't use it by dependency
a
OK thanks - that’s what I feared. It’s a shame, because a lot of effort has been invested in writing the infrastructure to support good testing and it should be easy to write tests for new operators that you write yourself
to answer my own question: https://github.com/cashapp/turbine does the job nicely - by Jake Wharton, no less!