Add annotation to prevent test invocation twice
Cause: it helps to fix double inversion of muted non-flaky tests result (KTI-216).
This commit is contained in:
@@ -69,6 +69,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
@@ -755,7 +756,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath) throws Exception {
|
||||
if (testCase != null) {
|
||||
if (testCase != null && !isRunTestOverridden(testCase)) {
|
||||
Function0<Unit> wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> {
|
||||
try {
|
||||
test.invoke(testDataFilePath);
|
||||
@@ -770,11 +771,20 @@ public class KotlinTestUtils {
|
||||
return;
|
||||
}
|
||||
}
|
||||
MuteWithFileKt.testWithMuteInFile(test, testCase).invoke(testDataFilePath);
|
||||
}
|
||||
|
||||
DoTest wrappedTest = testCase != null ?
|
||||
MuteWithFileKt.testWithMuteInFile(test, testCase) :
|
||||
MuteWithFileKt.testWithMuteInFile(test, "");
|
||||
wrappedTest.invoke(testDataFilePath);
|
||||
private static boolean isRunTestOverridden(TestCase testCase) {
|
||||
Class<?> type = testCase.getClass();
|
||||
while (type != null) {
|
||||
for (Annotation annotation : type.getDeclaredAnnotations()) {
|
||||
if (annotation.annotationType().equals(WithMutedInDatabaseRunTest.class)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
type = type.getSuperclass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static DoTest testWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, String ignoreDirective) throws Exception {
|
||||
|
||||
@@ -300,3 +300,5 @@ fun isIgnoredInDatabaseWithLog(testCase: TestCase): Boolean {
|
||||
fun TestCase.runTest(test: () -> Unit) {
|
||||
(wrapWithMuteInDatabase(this, test) ?: test).invoke()
|
||||
}
|
||||
|
||||
annotation class WithMutedInDatabaseRunTest
|
||||
|
||||
@@ -17,8 +17,8 @@ private val AUTOMATICALLY_GENERATE_FAIL_FILE_FOR_FAILED_TESTS: Boolean = false
|
||||
annotation class MuteExtraSuffix(val value: String = "")
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun testWithMuteInFile(test: DoTest, testCase: TestCase): DoTest {
|
||||
val extraSuffix = testCase.javaClass.getAnnotation(MuteExtraSuffix::class.java)?.value ?: ""
|
||||
fun testWithMuteInFile(test: DoTest, testCase: TestCase?): DoTest {
|
||||
val extraSuffix = testCase?.javaClass?.getAnnotation(MuteExtraSuffix::class.java)?.value ?: ""
|
||||
return testWithMuteInFile(test, extraSuffix)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user