diff --git a/testable-core/src/main/java/com/alibaba/testable/core/util/TestableUtil.java b/testable-core/src/main/java/com/alibaba/testable/core/util/TestableUtil.java index 0591449..bc85364 100644 --- a/testable-core/src/main/java/com/alibaba/testable/core/util/TestableUtil.java +++ b/testable-core/src/main/java/com/alibaba/testable/core/util/TestableUtil.java @@ -41,13 +41,11 @@ public class TestableUtil { * @return method name */ public static String currentTestCaseName(String testClassName) { - StackTraceElement[] stack = getMainThread().getStackTrace(); - for (int i = stack.length - 1; i >= 0; i--) { - if (stack[i].getClassName().equals(testClassName)) { - return stack[i].getMethodName(); - } + String testCaseName = findFirstMethodFromTestClass(testClassName, getMainThread().getStackTrace()); + if (testCaseName.isEmpty()) { + return findFirstMethodFromTestClass(testClassName, Thread.currentThread().getStackTrace()); } - return ""; + return testCaseName; } /** @@ -69,6 +67,15 @@ public class TestableUtil { return ""; } + private static String findFirstMethodFromTestClass(String testClassName, StackTraceElement[] stack) { + for (int i = stack.length - 1; i >= 0; i--) { + if (stack[i].getClassName().equals(testClassName)) { + return stack[i].getMethodName(); + } + } + return ""; + } + private static String getRealClassName(Class testClass) { String className = testClass.getName(); int posOfInnerClass = className.lastIndexOf('$');