Skip to content

Commit

Permalink
Adding JUnit5 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
philipplackner committed Jul 18, 2023
1 parent 2bfe13d commit 574218c
Show file tree
Hide file tree
Showing 47 changed files with 209 additions and 170 deletions.
5 changes: 3 additions & 2 deletions android/billing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import com.ivy.buildsrc.Billing
import com.ivy.buildsrc.Hilt

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`
id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
6 changes: 4 additions & 2 deletions android/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import com.ivy.buildsrc.AppCompat
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
AppCompat(api = true)
Expand Down
6 changes: 4 additions & 2 deletions android/file-system/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
6 changes: 4 additions & 2 deletions android/notifications/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import com.ivy.buildsrc.AndroidX
import com.ivy.buildsrc.Hilt


apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
5 changes: 3 additions & 2 deletions app-locked/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import com.ivy.buildsrc.Hilt

apply<com.ivy.buildsrc.IvyComposePlugin>()

plugins {
`android-library`
`kotlin-android`
id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyComposePlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id("com.google.firebase.crashlytics")
id("org.jetbrains.kotlin.android")
id("dagger.hilt.android.plugin")
id("io.kotest")
id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

android {
Expand Down
5 changes: 3 additions & 2 deletions backup/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyComposePlugin>()

plugins {
`android-library`
`kotlin-android`
id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyComposePlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
6 changes: 4 additions & 2 deletions backup/base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
6 changes: 4 additions & 2 deletions backup/impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"
}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
7 changes: 5 additions & 2 deletions backup/old/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"

}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
15 changes: 10 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ plugins {
// ./gradlew dependencyUpdates // Simple report in the console
// ./gradlew dependencyUpdates -DoutputFormatter=html,json,xml // Report in console & generate files accordingly
id("com.github.ben-manes.versions") version "0.39.0"

// Kotest Plugin
// https://github.com/kotest/kotest-gradle-plugin
id("io.kotest") version "0.3.8"
}

tasks {
Expand Down Expand Up @@ -44,4 +40,13 @@ fun isNonStable(version: String): Boolean {
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
}

tasks.register("printPlugins") {
doLast {
println("Plugins applied in project '${project.name}':")
project.plugins.forEach {
println(it::class.java.name)
}
}
}
13 changes: 1 addition & 12 deletions buildSrc/src/main/java/com/ivy/buildsrc/IvyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ abstract class IvyPlugin : Plugin<Project> {
addKotlinCompilerArgs(project)
setProjectSdkVersions(project)

kotest(project)
// Robolectric doesn't integrate well with JUnit5 and Kotest
// robolectric(project)
androidTest(project)
lint(project)
kspSourceSets(project)
}

private fun kotest(project: Project) {
val library = project.androidLibrary()
library.testOptions {
unitTests.all {
it.useJUnitPlatform()
}
}
}

// private fun robolectric(project: Project) {
// project.androidLibrary().testOptions {
// unitTests.isIncludeAndroidResources = true
Expand Down Expand Up @@ -57,11 +47,10 @@ abstract class IvyPlugin : Plugin<Project> {
plugin("kotlin-android")
plugin("kotlin-kapt")
plugin("dagger.hilt.android.plugin")
plugin("io.kotest")
plugin("com.google.devtools.ksp")

//TODO: Enable if we migrate to kotlinx serialization
// plugin("kotlinx-serialization")
// plugin("kotlinx-serialization")
}
}

Expand Down
77 changes: 12 additions & 65 deletions buildSrc/src/main/java/com/ivy/buildsrc/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ object Versions {
const val composeCoil = "2.2.2"
// endregion

//https://arrow-kt.io/docs/quickstart/
const val arrow: String = "1.1.5"

//https://kotest.io/
const val kotest: String = "5.4.2"

//https://github.com/kotest/kotest-extensions-arrow
const val kotestArrow = "1.3.0"
const val junitJupiter: String = "5.8.2"
const val junitJupiter: String = "5.9.3"
const val junit5GradlePlugin = "1.9.3.0"

//https://developer.android.com/training/dependency-injection/hilt-android
//WARNING: Update hilt gradle plugin from buildSrc
Expand Down Expand Up @@ -163,6 +156,10 @@ object Versions {
const val testCore = "1.4.0"
const val testJunitExt = "1.1.3"
const val testRunner = "1.4.0"

// AssertK
const val assertK = "0.26.1"

// endregion
}

Expand Down Expand Up @@ -459,38 +456,23 @@ fun DependencyHandler.Timber(api: Boolean) {
dependency("com.jakewharton.timber:timber:${Versions.timber}", api = api)
}

fun DependencyHandler.FunctionalProgramming(api: Boolean) {
Arrow(api)
}

fun DependencyHandler.RealmDb() {
implementation("io.realm.kotlin:library-base:${Versions.realm}")
}

/**
* Functional Programming with Kotlin
*/
fun DependencyHandler.Arrow(
api: Boolean
) {
dependency(platform("io.arrow-kt:arrow-stack:${Versions.arrow}"), api = api)
dependency("io.arrow-kt:arrow-core", api = api)
dependency("io.arrow-kt:arrow-fx-coroutines", api = api)
dependency("io.arrow-kt:arrow-fx-stm", api = api)
fun DependencyHandler.JUnit5() {
testImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.junitJupiter}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.junitJupiter}")
}

// Optics
dependency("io.arrow-kt:arrow-optics", api = api)
ksp("io.arrow-kt:arrow-optics-ksp-plugin:${Versions.arrow}")
fun DependencyHandler.AssertK() {
testImplementation("com.willowtreeapps.assertk:assertk:${Versions.assertK}")
}

fun DependencyHandler.Testing(
commonTest: Boolean = true,
commonAndroidTest: Boolean = true
) {
Kotest()
// Robolectric doesn't integrate well with JUnit5 and Kotest
// Robolectric(api = false)

if (commonTest) {
testImplementation(project(":common:test"))
}
Expand Down Expand Up @@ -518,41 +500,6 @@ fun DependencyHandler.AndroidXTest(
dependency("androidx.test:runner:${Versions.testRunner}")
}

/**
* Kotlin Property-based testing
*/
fun DependencyHandler.Kotest() {
val api = false //TODO: Kotest API does not work
//junit5 is required!
testDependency("org.junit.jupiter:junit-jupiter:${Versions.junitJupiter}", api = api)
testDependency("io.kotest:kotest-runner-junit5:${Versions.kotest}", api = api)

testDependency("io.kotest:kotest-assertions-core:${Versions.kotest}", api = api)
androidTestDependency("io.kotest:kotest-assertions-core:${Versions.kotest}", api = api)

testDependency("io.kotest:kotest-property:${Versions.kotest}", api = api)
testDependency("io.kotest:kotest-framework-datatest:${Versions.kotest}", api = api)
testDependency("io.kotest:kotest-framework-api-jvm:${Versions.kotest}", api = api)
testImplementation("io.kotest:kotest-framework-engine-jvm:${Versions.kotest}")

//otherwise Kotest doesn't work...
testDependency("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}", api = api)


// Kotest - Arrow extensions
val kotestArrow = Versions.kotestArrow
testDependency(
"io.kotest.extensions:kotest-assertions-arrow:$kotestArrow", api = api
)
testDependency(
"io.kotest.extensions:kotest-assertions-arrow-fx-coroutines:$kotestArrow",
api = api
)
testDependency(
"io.kotest.extensions:kotest-property-arrow:$kotestArrow", api = api
)
}

fun DependencyHandler.Robolectric(api: Boolean) {
testDependency("org.robolectric:robolectric:${Versions.robolectric}", api = api)
testDependency("junit:junit:${Versions.robolectricJunit}", api = api)
Expand Down
7 changes: 5 additions & 2 deletions categories/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import com.ivy.buildsrc.Hilt
import com.ivy.buildsrc.Testing

apply<com.ivy.buildsrc.IvyComposePlugin>()

plugins {
`android-library`

id("de.mannodermaus.android-junit5") version "1.9.3.0"

}

apply<com.ivy.buildsrc.IvyComposePlugin>()

dependencies {
Hilt()
implementation(project(":common:main"))
Expand Down
7 changes: 5 additions & 2 deletions common/android-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import com.ivy.buildsrc.*

apply<com.ivy.buildsrc.IvyPlugin>()

plugins {
`android-library`
`kotlin-android`

id("de.mannodermaus.android-junit5") version "1.9.3.0"

}

apply<com.ivy.buildsrc.IvyPlugin>()

dependencies {
Hilt()
HiltTesting(
Expand Down
Loading

0 comments on commit 574218c

Please sign in to comment.