Updated on 2026-08-14
This commit is contained in:
parent
0221d36f60
commit
3f7a1e0d20
3 changed files with 49 additions and 73 deletions
|
|
@ -1,6 +1,3 @@
|
|||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
plugins {
|
||||
alias(deps.plugins.kotlin.android) apply false
|
||||
alias(deps.plugins.kotlin.jvm) apply false
|
||||
|
|
@ -33,83 +30,13 @@ interface Injected {
|
|||
val fs: FileSystemOperations
|
||||
}
|
||||
|
||||
data class TestStats(
|
||||
val total: Long = 0,
|
||||
val passed: Long = 0,
|
||||
val failed: Long = 0,
|
||||
val skipped: Long = 0,
|
||||
)
|
||||
|
||||
val testResultsByModule = ConcurrentHashMap<String, TestStats>()
|
||||
|
||||
// Test task to run unit tests for debug/googleDebug variant (Android) and all JVM modules
|
||||
val unitTest by tasks.registering {
|
||||
group = "verification"
|
||||
description = "Run unit tests for debug/googleDebug variant and all JVM modules"
|
||||
|
||||
doLast {
|
||||
if (testResultsByModule.isNotEmpty()) {
|
||||
val totalStats = testResultsByModule.values.fold(TestStats()) { acc, stats ->
|
||||
TestStats(
|
||||
total = acc.total + stats.total,
|
||||
passed = acc.passed + stats.passed,
|
||||
failed = acc.failed + stats.failed,
|
||||
skipped = acc.skipped + stats.skipped,
|
||||
)
|
||||
}
|
||||
|
||||
println("\n" + "=".repeat(80))
|
||||
println("TEST SUMMARY")
|
||||
println("=".repeat(80))
|
||||
|
||||
testResultsByModule.toSortedMap().forEach { (module, stats) ->
|
||||
println(" $module: ${stats.total} tests (${stats.passed} passed, ${stats.failed} failed, ${stats.skipped} skipped)")
|
||||
}
|
||||
|
||||
println("-".repeat(80))
|
||||
println("TOTAL: ${totalStats.total} tests in ${testResultsByModule.size} modules")
|
||||
println(" Passed: ${totalStats.passed}")
|
||||
println(" Failed: ${totalStats.failed}")
|
||||
println(" Skipped: ${totalStats.skipped}")
|
||||
println("=".repeat(80))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test Logging and testCI dependencies
|
||||
subprojects {
|
||||
tasks.withType<Test>().configureEach {
|
||||
println("Test task scheduled: $path")
|
||||
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
showStandardStreams = true
|
||||
|
||||
afterSuite(KotlinClosure2<TestDescriptor, TestResult, Unit>({ desc, result ->
|
||||
if (desc.parent == null) { // will match the outermost suite
|
||||
testResultsByModule[path] = TestStats(
|
||||
total = result.testCount,
|
||||
passed = result.successfulTestCount,
|
||||
failed = result.failedTestCount,
|
||||
skipped = result.skippedTestCount,
|
||||
)
|
||||
|
||||
val output =
|
||||
"Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
|
||||
val startItem = "| "
|
||||
val endItem = " |"
|
||||
val repeatLength = startItem.length + output.length + endItem.length
|
||||
println(
|
||||
"\n" + "-".repeat(repeatLength) + "\n" + startItem + output + endItem + "\n" + "-".repeat(
|
||||
repeatLength
|
||||
)
|
||||
)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
// Register testCI dependencies
|
||||
// App module
|
||||
plugins.withId("com.android.application") {
|
||||
afterEvaluate {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ import org.gradle.api.Project
|
|||
internal fun Project.configure() {
|
||||
configureKotlinCompilerOptions()
|
||||
configureDetektRules()
|
||||
configureTestLogging()
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.tangem.plugin.configuration.configurations
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.api.tasks.testing.TestDescriptor
|
||||
import org.gradle.api.tasks.testing.TestListener
|
||||
import org.gradle.api.tasks.testing.TestResult
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import java.io.Serializable
|
||||
|
||||
internal fun Project.configureTestLogging() {
|
||||
tasks.withType(Test::class.java).configureEach {
|
||||
println("Test task scheduled: $path")
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
showStandardStreams = true
|
||||
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
||||
}
|
||||
addTestListener(TestSuiteLogger(path))
|
||||
}
|
||||
}
|
||||
|
||||
private class TestSuiteLogger(private val taskPath: String) : TestListener, Serializable {
|
||||
override fun beforeSuite(suite: TestDescriptor) {}
|
||||
|
||||
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
|
||||
if (suite.parent == null) {
|
||||
val output =
|
||||
"$taskPath - Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
|
||||
val startItem = "| "
|
||||
val endItem = " |"
|
||||
val repeatLength = startItem.length + output.length + endItem.length
|
||||
println(
|
||||
"\n" + "-".repeat(repeatLength) + "\n" + startItem + output + endItem + "\n" + "-".repeat(
|
||||
repeatLength,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeTest(testDescriptor: TestDescriptor) {}
|
||||
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {}
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue