Support mute tests in kotlin-gradle-plugin-integration-tests (KTI-234)
#KTI-234 Fixed
This commit is contained in:
@@ -6,10 +6,13 @@
|
||||
package org.jetbrains.kotlin.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.test.mutes.*
|
||||
import org.jetbrains.kotlin.test.mutes.MutedTest
|
||||
import org.jetbrains.kotlin.test.mutes.getMutedTest
|
||||
import org.jetbrains.kotlin.test.mutes.mutedSet
|
||||
import org.junit.internal.runners.statements.InvokeMethod
|
||||
import org.junit.runner.Runner
|
||||
import org.junit.runner.notification.RunNotifier
|
||||
import org.junit.runners.BlockJUnit4ClassRunner
|
||||
import org.junit.runners.model.FrameworkMethod
|
||||
import org.junit.runners.model.Statement
|
||||
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters
|
||||
@@ -84,24 +87,7 @@ class RunnerFactoryWithMuteInDatabase : ParametersRunnerFactory {
|
||||
}
|
||||
|
||||
override fun methodInvoker(method: FrameworkMethod, test: Any?): Statement {
|
||||
return object : InvokeMethod(method, test) {
|
||||
override fun evaluate() {
|
||||
val methodClass = method.declaringClass
|
||||
val methodKey = parametrizedMethodKey(method, name)
|
||||
val mutedTest = getMutedTest(methodClass, methodKey) ?: getMutedTest(methodClass, method.method.name)
|
||||
if (isPresentedInDatabaseWithoutFailMarker(mutedTest)) {
|
||||
if (mutedTest?.isFlaky == true) {
|
||||
super.evaluate()
|
||||
return
|
||||
} else {
|
||||
val testKey = testKey(methodClass, methodKey)
|
||||
invertMutedTestResultWithLog({ super.evaluate() }, testKey)
|
||||
return
|
||||
}
|
||||
}
|
||||
super.evaluate()
|
||||
}
|
||||
}
|
||||
return MethodInvokerWithMutedTests(method, test, mainMethodKey = parametrizedMethodKey(method, name))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +95,44 @@ class RunnerFactoryWithMuteInDatabase : ParametersRunnerFactory {
|
||||
private fun parametrizedMethodKey(child: FrameworkMethod, parametersName: String) = "${child.method.name}$parametersName"
|
||||
}
|
||||
|
||||
class MethodInvokerWithMutedTests(val method: FrameworkMethod, val test: Any?, val mainMethodKey: String? = null) : InvokeMethod(method, test) {
|
||||
override fun evaluate() {
|
||||
val methodClass = method.declaringClass
|
||||
val mutedTest =
|
||||
mainMethodKey?.let { getMutedTest(methodClass, it) }
|
||||
?: getMutedTest(methodClass, method.method.name)
|
||||
|
||||
if (mutedTest != null && isPresentedInDatabaseWithoutFailMarker(mutedTest)) {
|
||||
if (mutedTest.isFlaky) {
|
||||
super.evaluate()
|
||||
return
|
||||
} else {
|
||||
val testKey = testKey(methodClass, mutedTest.methodKey)
|
||||
invertMutedTestResultWithLog({ super.evaluate() }, testKey)
|
||||
return
|
||||
}
|
||||
}
|
||||
super.evaluate()
|
||||
}
|
||||
}
|
||||
|
||||
class RunnerWithMuteInDatabase(klass: Class<*>?) : BlockJUnit4ClassRunner(klass) {
|
||||
override fun isIgnored(child: FrameworkMethod): Boolean {
|
||||
return super.isIgnored(child) || isMutedInDatabaseWithLog(child.declaringClass, child.name)
|
||||
}
|
||||
|
||||
override fun runChild(method: FrameworkMethod, notifier: RunNotifier) {
|
||||
val testKey = testKey(method.declaringClass, method.name)
|
||||
notifier.withAutoMuteListener(testKey) {
|
||||
super.runChild(method, notifier)
|
||||
}
|
||||
}
|
||||
|
||||
override fun methodInvoker(method: FrameworkMethod, test: Any?): Statement {
|
||||
return MethodInvokerWithMutedTests(method, test)
|
||||
}
|
||||
}
|
||||
|
||||
private fun invertMutedTestResultWithLog(f: () -> Unit, testKey: String) {
|
||||
var isTestGreen = true
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user