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

alexfacciorusso

01/25/2019, 11:12 AM
Hi guys! Does anyone know how to suppress the tests to be executed for the iOS platform on a shared module on
build
? In particular, we are using MockK for mocking, that hasn’t got native support, so we’d like only the jvm/android tests to be executed when the
build
task is called on Gradle
I have temporarily fixed this with
linkTestDebugExecutableIOS.enabled = false
at the end of the
build.gradle
multiplatform file, but I’m pretty sure there’s a proper way of doing that
e

einar

01/25/2019, 1:39 PM
I’m having the same issue. Thanks for the temporary workaround tip. I cannot however get that to work. You’re placing this at the bottom of the
common
gradle file? I just get
Copy code
Could not get unknown property 'linkTestDebugExecutableIOS' for project ':common' of type org.gradle.api.Project.
tried disabling it like this:
Copy code
tasks.whenTaskAdded {task ->
    if(task.name.contains("linkTestDebugExecutableIos")) {
        task.enabled = false
    }
}
but that has no effect sadly
r

russhwolf

01/25/2019, 2:48 PM
Sounds like you're trying to suppress all tests globally on iOS, but if it works for to do it on a per-test basis instead, you could try creating an
expect annotation class
and have it typealias to
@Ignore
on iOS and no-op elsewhere. Or do the inverse and typalias a new annotation to
@Test
on everywhere but iOS. I've been toying with putting out a library that does this for different platforms, if it seems useful.
a

alexfacciorusso

01/25/2019, 2:54 PM
@russhwolf nice one, I like your solution as well
@einar by the way, I've put the line
linkTestDebugExecutableIOS.enabled = false // temporary fix for ios tests failing due to mockk
at the end of the gradle common file. Just wanted to notice I'm still using the old
Copy code
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos")    \
                                 ? presets.iosArm64 : presets.iosX64

        fromPreset(iOSTarget, 'iOS') {
            compilations.main.outputKinds('FRAMEWORK')
        }
for setting up the ios preset
e

einar

01/25/2019, 9:38 PM
@russhwolf yeah it makes a lot of sense to do it that way. How would this be done? By adding an expect class in commonTest (which is where I would put such an annotation class?), where do I put The actual class? If I add the actual class in iosTest it is required that I add the Kotlin test dependency in order to typealias that class to an @Ignore? (or if I want to go the other way)
r

russhwolf

01/25/2019, 9:49 PM
Yeah you'd need to use kotin.test still. You could do something like
Copy code
@OptionalExpectation
expect annotation class IosIgnore
in your common source, and then
Copy code
actual typalias IosIgnore = kotlin.test.Ignore
in your ios source. Then any test function in common that you annotate with
@IosIgnore
will be ignored on ios but still run on all other platforms.
👍 2