mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +08:00
[build] Use JUnit5 on Android
This commit is contained in:
parent
a2d50ec03a
commit
2cf97a181f
@ -14,10 +14,7 @@ import com.google.gradle.osdetector.OsDetector
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.getting
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME
|
||||
@ -203,6 +200,12 @@ fun Project.configureJvmTargetsHierarchical() {
|
||||
// this can cause problems on sync
|
||||
// for (s in arrayOf("androidDebug", "androidRelease")) {
|
||||
// sourceSets.all { if (name in s) dependsOn(androidMain) }
|
||||
// }
|
||||
|
||||
// we should have added a "androidBaseTest" (or "androidTest") for "androidUnitTest" and "androidInstrumentedTest",
|
||||
// but this currently cause bugs in IntelliJ (2023.2)
|
||||
// val androidBaseTest = sourceSets.maybeCreate("androidBaseTest").apply {
|
||||
// dependsOn(jvmBaseTest)
|
||||
// }
|
||||
val androidUnitTest by sourceSets.getting {
|
||||
dependsOn(jvmBaseTest)
|
||||
@ -279,8 +282,33 @@ fun Project.configureAndroidTarget() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// if (USE_JUNIT5_FOR_ANDROID_TEST) {
|
||||
// extensions.getByType(LibraryExtension::class.java).apply {
|
||||
// defaultConfig {
|
||||
// // 1) Make sure to use the AndroidJUnitRunner, or a subclass of it. This requires a dependency on androidx.test:runner, too!
|
||||
// testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
// // 2) Connect JUnit 5 to the runner
|
||||
// testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// dependencies {
|
||||
// // 4) Jupiter API & Test Runner, if you don't have it already
|
||||
// "androidTestImplementation"("androidx.test:runner:1.5.2")
|
||||
// "androidTestImplementation"("org.junit.jupiter:junit-jupiter-api:5.9.2")
|
||||
// runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
||||
//
|
||||
// // 5) The instrumentation test companion libraries
|
||||
// "androidTestImplementation"("de.mannodermaus.junit5:android-test-core:1.3.0")
|
||||
// "androidTestRuntimeOnly"("de.mannodermaus.junit5:android-test-runner:1.3.0")
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private const val USE_JUNIT5_FOR_ANDROID_TEST = true
|
||||
|
||||
|
||||
/**
|
||||
* ```
|
||||
|
@ -17,7 +17,7 @@ kotlin.native.binary.memoryModel=experimental
|
||||
systemProp.org.gradle.internal.publish.checksums.insecure=true
|
||||
gnsp.disableApplyOnlyOnRootProjectEnforcement=true
|
||||
# We may target 15 with Kotlin 1.5 IR
|
||||
mirai.android.target.api.level=24
|
||||
mirai.android.target.api.level=26
|
||||
# Enable if you want to use mavenLocal for both Gradle plugin and project dependencies resolutions.
|
||||
systemProp.use.maven.local=false
|
||||
org.gradle.caching=true
|
||||
@ -25,5 +25,5 @@ kotlin.native.ignoreIncorrectDependencies=true
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.mpp.stability.nowarn=true
|
||||
kotlin.mpp.androidSourceSetLayoutVersion=2
|
||||
|
||||
android.disableAutomaticComponentCreation=true
|
||||
android.disableAutomaticComponentCreation=true
|
||||
android.useAndroidX=true
|
@ -117,7 +117,7 @@ if (tasks.findByName("androidMainClasses") != null) {
|
||||
group = "verification"
|
||||
this.mustRunAfter("androidMainClasses")
|
||||
}
|
||||
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
|
||||
tasks.getByName("androidBaseTest").dependsOn("checkAndroidApiLevel")
|
||||
}
|
||||
|
||||
configureMppPublishing()
|
||||
|
@ -90,20 +90,20 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
//if (tasks.findByName("androidMainClasses") != null) {
|
||||
// tasks.register("checkAndroidApiLevel") {
|
||||
// doFirst {
|
||||
// analyzes.AndroidApiLevelCheck.check(
|
||||
// buildDir.resolve("classes/kotlin/android/main"),
|
||||
// project.property("mirai.android.target.api.level")!!.toString().toInt(),
|
||||
// project
|
||||
// )
|
||||
// }
|
||||
// group = "verification"
|
||||
// this.mustRunAfter("androidMainClasses")
|
||||
// }
|
||||
// tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
|
||||
//}
|
||||
if (tasks.findByName("androidMainClasses") != null) {
|
||||
tasks.register("checkAndroidApiLevel") {
|
||||
doFirst {
|
||||
analyzes.AndroidApiLevelCheck.check(
|
||||
buildDir.resolve("classes/kotlin/android/main"),
|
||||
project.property("mirai.android.target.api.level")!!.toString().toInt(),
|
||||
project
|
||||
)
|
||||
}
|
||||
group = "verification"
|
||||
this.mustRunAfter("androidMainClasses")
|
||||
}
|
||||
tasks.getByName("androidBaseTest").dependsOn("checkAndroidApiLevel")
|
||||
}
|
||||
|
||||
//configureMppPublishing()
|
||||
|
||||
|
@ -22,6 +22,7 @@ plugins {
|
||||
id("me.him188.kotlin-dynamic-delegation")
|
||||
// id("me.him188.maven-central-publish")
|
||||
`maven-publish`
|
||||
id("de.mannodermaus.android-junit5") version "1.8.2.1"
|
||||
}
|
||||
|
||||
description = "Mirai Protocol implementation for QQ Android"
|
||||
@ -243,7 +244,7 @@ if (tasks.findByName("androidMainClasses") != null) {
|
||||
group = "verification"
|
||||
this.mustRunAfter("androidMainClasses")
|
||||
}
|
||||
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
|
||||
tasks.getByName("androidBaseTest").dependsOn("checkAndroidApiLevel")
|
||||
}
|
||||
|
||||
configureMppPublishing()
|
||||
|
@ -11,7 +11,7 @@ package net.mamoe.mirai.internal.test
|
||||
|
||||
//import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertIs
|
||||
|
||||
internal actual fun initPlatform() {
|
||||
@ -29,7 +29,7 @@ private val init: Unit by lazy {
|
||||
|
||||
internal actual class PlatformInitializationTest : AbstractTest() {
|
||||
|
||||
@Test
|
||||
@org.junit.jupiter.api.Test
|
||||
actual fun test() {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
assertIs<net.mamoe.mirai.internal.utils.StdoutLogger>(MiraiLogger.Factory.create(this::class, "1"))
|
||||
|
Loading…
Reference in New Issue
Block a user