I am currently working on a kotlin mmp which for ios and android. I put all platform independent logics in CommonMain, and write some tests in CommonTest.
This is the file structure
src
├── commonMain
│ └── kotlin
│ └──dir/someClass.kt
├── commonTest
│ └── kotlin
│ └──dir/someClassTest.kt
…
The tests can run by right click the file or method, but cannot be trigger with gradle tasks, I want to run them in CI pipeline so I need to run them in command line.
How should I config the gradle file to make them runnable in command line?
I dont know why the icon is different for androidMain/androidTest from the rest.
And this is my build.gradle
group 'com.myProject'
version ‘0.0.1’
apply plugin: 'org.jetbrains.kotlin.multiplatform' apply plugin: 'kotlinx-serialization' apply plugin: 'com.android.library' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: "com.squareup.sqldelight" apply plugin: 'com.codingfeline.buildkonfig' sqldelight { MyDb { packageName = "com.project.database" } } repositories { jcenter() mavenCentral() } android { task copySdkClasses(type: Copy) { from "build/tmp/kotlin-classes/debug" into "build/intermediates/classes/debug" } compileSdkVersion 28 defaultConfig { minSdkVersion 24 targetSdkVersion 28 versionCode 1 versionName "1.0" ndk { abiFilters 'arm64-v8a' } } buildTypes { release { minifyEnabled false } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } configurations.all { resolutionStrategy { cacheDynamicVersionsFor 0, "seconds" cacheChangingModulesFor 0, "seconds" } } kotlin { android("android") // This is for iPhone emulator // Switch here to iosArm64 (or iosArm32) to build library for iPhone device iosArm64("ios") { binaries { framework("mysdk") } } sourceSets { commonMain { dependencies { implementation kotlin('stdlib-common') implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" implementation "com.soywiz.korlibs.klock:klock:$klock_version" implementation "io.ktor:ktor-client-core:$ktor_version" implementation "io.ktor:ktor-client-json:$ktor_version" implementation "io.ktor:ktor-client-serialization:$ktor_version" } } commonTest { dependencies { implementation kotlin('test') implementation kotlin('test-junit') implementation kotlin('test-common') implementation kotlin('test-annotations-common') implementation "io.mockk:mockk:$mockk_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "com.soywiz.korlibs.klock:klock:$klock_version" implementation "io.ktor:ktor-client-core:$ktor_version" } } androidMain { dependencies { implementation kotlin('stdlib') implementation "androidx.recyclerview:recyclerview:$androidx_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "io.ktor:ktor-client-okhttp:$ktor_version" implementation "io.ktor:ktor-client-json-jvm:$ktor_version" implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version" implementation "com.github.yandextaxitech:binaryprefs:$binary_prefs" implementation "com.squareup.sqldelight:android-driver:$sqldelight_version" implementation "androidx.core:core:$androidx_core_version" implementation "com.google.android.material:material:$androidx_version" } } androidTest { dependencies { implementation kotlin('test') implementation kotlin('test-junit') implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" } } iosMain { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version" implementation "io.ktor:ktor-client-ios-iosarm64:$ktor_version" implementation "io.ktor:ktor-client-core-iosarm64:$ktor_version" implementation "io.ktor:ktor-client-json-iosarm64:$ktor_version" implementation "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" implementation "com.squareup.sqldelight:ios-driver:$sqldelight_version" } } } } if (project.findProperty("buildkonfig.flavor") == null && file("local.properties").exists()){ Properties properties = new Properties() properties.load(project.file("local.properties").newDataInputStream()) String flavor = properties.getProperty("buildkonfig.flavor", "") project.ext.setProperty("buildkonfig.flavor", flavor) } buildkonfig { ... } configurations { compileClasspath } dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' }