[#31] feat: 테스트 결과 colorMode 적용
- buildSrc plugin 내용 클래스 패키지 분리 - colorMode 적용(추후 profile에 따라 처리 필요)
This commit is contained in:
@@ -19,7 +19,7 @@ pipeline {
|
||||
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh './gradlew clean :dongne-service-api:test --stacktrace'
|
||||
sh './gradlew clean :dongne-service-api:test'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
import plugin.BuildLifecyclePlugin
|
||||
import plugin.TestContainer
|
||||
import plugin.TestSummary
|
||||
import task.test.TestContainer
|
||||
import task.test.TestLoggingUtils
|
||||
import task.test.TestSummary
|
||||
|
||||
val bootJar: BootJar by tasks
|
||||
bootJar.enabled = false
|
||||
@@ -99,7 +100,7 @@ subprojects {
|
||||
showStackTraces = true
|
||||
}
|
||||
|
||||
ignoreFailures = true
|
||||
// ignoreFailures = true
|
||||
|
||||
addTestListener(object : TestListener {
|
||||
override fun beforeSuite(desc: TestDescriptor) {}
|
||||
@@ -119,7 +120,7 @@ subprojects {
|
||||
override fun beforeTest(desc: TestDescriptor) {}
|
||||
// handling after each test finished
|
||||
override fun afterTest(desc: TestDescriptor, result: TestResult) {
|
||||
TestContainer.printEachResult(desc, result)
|
||||
TestLoggingUtils.printEachResult(desc, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.tooling.events.FinishEvent
|
||||
import org.gradle.tooling.events.OperationCompletionListener
|
||||
import org.gradle.tooling.events.task.TaskFinishEvent
|
||||
import task.test.TestContainer
|
||||
import task.test.TestLoggingUtils
|
||||
|
||||
abstract class BuildOperationService : BuildService<BuildOperationService.Params>, OperationCompletionListener {
|
||||
interface Params : BuildServiceParameters {
|
||||
@@ -17,7 +19,8 @@ abstract class BuildOperationService : BuildService<BuildOperationService.Params
|
||||
}
|
||||
|
||||
if (event.descriptor.taskPath == parameters.lastTaskPath) {
|
||||
TestContainer.printTotalResult(TestContainer.testResults)
|
||||
TestLoggingUtils.printTotalResult(TestContainer.testResults)
|
||||
TestContainer.testResults = null
|
||||
}
|
||||
}
|
||||
}
|
||||
8
buildSrc/src/main/kotlin/task/test/TestContainer.kt
Normal file
8
buildSrc/src/main/kotlin/task/test/TestContainer.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package task.test
|
||||
|
||||
class TestContainer {
|
||||
companion object {
|
||||
var testResults: TestSummary? = null
|
||||
const val colorMode: Boolean = false
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
package plugin
|
||||
package task.test
|
||||
|
||||
import org.gradle.api.tasks.testing.TestDescriptor
|
||||
import org.gradle.api.tasks.testing.TestResult
|
||||
import org.gradle.api.tasks.testing.TestResult.*
|
||||
|
||||
class TestContainer {
|
||||
class TestLoggingUtils {
|
||||
companion object {
|
||||
var testResults: TestSummary? = null
|
||||
|
||||
const val ANSI_RESET = "\u001B[0m"
|
||||
const val ANSI_GREEN = "\u001B[32m"
|
||||
const val ANSI_RED = "\u001B[31m"
|
||||
@@ -23,12 +20,11 @@ class TestContainer {
|
||||
|${
|
||||
summary.toLogList().joinToString("│\n│", "│", "│") {
|
||||
val coloredResult = colorResultType(summary.result.resultType)
|
||||
val str = "$it${" ".repeat(maxLength - it.length)}"
|
||||
"$it${" ".repeat(maxLength - it.length)}"
|
||||
.replace(
|
||||
oldValue = coloredResult.first.toString(),
|
||||
newValue = coloredResult.second
|
||||
)
|
||||
str
|
||||
}
|
||||
}
|
||||
|└${"─".repeat(maxLength)}┘
|
||||
@@ -37,18 +33,22 @@ class TestContainer {
|
||||
}
|
||||
|
||||
fun printEachResult(desc: TestDescriptor, result: TestResult) {
|
||||
println("[${desc.className}] ${desc.displayName} result: ${colorResultType(result.resultType).second}")
|
||||
println("[${desc.className}] ${desc.displayName} >> result: ${colorResultType(result.resultType).second}")
|
||||
}
|
||||
|
||||
fun colorResultType(resultType: ResultType): Pair<ResultType, String> {
|
||||
fun colorResultType(resultType: TestResult.ResultType): Pair<TestResult.ResultType, String> {
|
||||
if (TestContainer.colorMode.not()) {
|
||||
return resultType to "${resultType}"
|
||||
}
|
||||
|
||||
val color = when (resultType) {
|
||||
ResultType.SUCCESS -> ANSI_GREEN
|
||||
ResultType.FAILURE -> ANSI_RED
|
||||
TestResult.ResultType.SUCCESS -> ANSI_GREEN
|
||||
TestResult.ResultType.FAILURE -> ANSI_RED
|
||||
else -> ""
|
||||
}
|
||||
|
||||
return resultType to if (color.isNotEmpty()) {
|
||||
"${color}${resultType}${ANSI_RESET}"
|
||||
"${color}${resultType}$ANSI_RESET"
|
||||
} else "${resultType}"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package plugin
|
||||
package task.test
|
||||
|
||||
import org.gradle.api.tasks.testing.TestResult
|
||||
|
||||
Reference in New Issue
Block a user