Skip to content

Instantly share code, notes, and snippets.

@tylergannon
Last active May 8, 2022 23:34
Show Gist options
  • Save tylergannon/9d88c621abb0607bbe86882b2de6bfb2 to your computer and use it in GitHub Desktop.
Save tylergannon/9d88c621abb0607bbe86882b2de6bfb2 to your computer and use it in GitHub Desktop.
Kotlin multiplatform with compose tests
@file:Suppress("UnstableApiUsage")
import java.util.Properties
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("com.android.library")
id("maven-publish")
}
group = "com.myapp.common"
version = "1.0.0"
val mvnArtifactId = name
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://jitpack.io")
}
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
}
}
dependencies {
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.appcompat:appcompat:1.4.1")
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
testRuns["test"].executionTask.configure {
// useJUnitPlatform()
}
}
android {
publishLibraryVariants = listOf("release", "debug")
}
sourceSets {
val commonMain by getting {
dependencies {
api(kotlin("stdlib-common"))
api(compose.runtime)
api(compose.foundation)
api(compose.material)
api("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation(kotlin("test-common"))
implementation("org.jetbrains.compose.ui:ui-test-junit4:1.2.0-alpha01-dev620")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1")
implementation("io.kotest:kotest-assertions-core:5.2.3")
}
}
val jvmMain by getting {
dependencies {
implementation(compose.desktop.currentOs)
}
}
val jvmTest by getting {
dependencies {
implementation("junit:junit:4.13.2")
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.5.0")
val androidComposeVersion = "1.2.0-alpha08"
implementation("androidx.compose.material:material:$androidComposeVersion")
}
}
val androidTest by getting {
dependencies {
implementation("junit:junit:4.13.2")
implementation(kotlin("test-android-junit"))
implementation("androidx.test:core:1.4.0")
implementation("androidx.test:runner:1.4.0")
implementation("androidx.test:rules:1.4.0")
implementation("org.robolectric:robolectric:4.7.3")
implementation("androidx.compose.ui:ui-test-junit4:1.1.1")
implementation("androidx.compose.ui:ui-test-manifest:1.2.0-alpha08")
}
}
}
}
android {
compileSdk = 31
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
buildFeatures {
compose = true
viewBinding = true
}
defaultConfig {
minSdk = 26
targetSdk = 31
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
lint {
this.isAbortOnError = false
this.isCheckTestSources = false
this.isCheckReleaseBuilds = false
}
testOptions {
unitTests {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-alpha01-dev679"
}
// kotlinOptions {
// jvmTarget = "1.8"
// }
}
class ModelContainerHostTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test fun firstTest() = runBlocking {
composeTestRule.setContent {
@Composable fun doAThing() = 1
doAThing() shouldBeExactly 2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment