egorand
05/04/2020, 5:38 PMexpect class
with a common test suite and implementations for Android and iOS. Sadly, the Android implementation uses Android SDK types which are mocked out when running the tests on the local JVM, so I need to slap a @RunWith(RobolectricTestRunner::class)
on the test class declaration to make it work. Unfortunately, the common code doesn't know anything about test runners, so having this annotation directly on the test class in the common module would require a lot of complicated expect-actualing. I found the following example: https://github.com/Kotlin/mpp-example/blob/master/greeting/src/androidLibTest/kotlin/CalculatorTestJavaHelper.kt, the idea is to make the common test open
and extend it in androidTest
, which allows attaching the @RunWith
annotation. The problem is that the example is actually trying to address a different issue (namely, being able to execute that test from the IDE) and doesn't prevent the common test from running and failing on Android. I figured out a way to @Ignore
the common test on Android only, but that's a pretty ugly hack. I wonder if there's a more straightforward solution.russhwolf
05/04/2020, 5:48 PM@OptionalExpectation
since you need to pass a parameter to the @RunWith()
annotation. You can leave your test class open, but you lose out on IDE integration since the implementation doesn't have the test declarations so there's no gutter icon to click on. Or you can do an `expect`/`actual` base class, where the Android actual
has the annotations and the other platforms no-op.egorand
05/04/2020, 6:02 PMrusshwolf
05/04/2020, 6:09 PMexpect abstract class BaseTest
android
@RunWith(...)
actual abstract class BaseTest
non-android
actual abstract class BaseTest
BaseTest
in commonKris Wong
05/04/2020, 6:26 PMrusshwolf
05/04/2020, 6:38 PMKris Wong
05/04/2020, 6:39 PM