mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-10 20:30:11 +08:00
also look current thread for test case name
This commit is contained in:
parent
92f9c27561
commit
35dbc1f497
@ -41,13 +41,11 @@ public class TestableUtil {
|
|||||||
* @return method name
|
* @return method name
|
||||||
*/
|
*/
|
||||||
public static String currentTestCaseName(String testClassName) {
|
public static String currentTestCaseName(String testClassName) {
|
||||||
StackTraceElement[] stack = getMainThread().getStackTrace();
|
String testCaseName = findFirstMethodFromTestClass(testClassName, getMainThread().getStackTrace());
|
||||||
for (int i = stack.length - 1; i >= 0; i--) {
|
if (testCaseName.isEmpty()) {
|
||||||
if (stack[i].getClassName().equals(testClassName)) {
|
return findFirstMethodFromTestClass(testClassName, Thread.currentThread().getStackTrace());
|
||||||
return stack[i].getMethodName();
|
|
||||||
}
|
}
|
||||||
}
|
return testCaseName;
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +67,15 @@ public class TestableUtil {
|
|||||||
return "";
|
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) {
|
private static String getRealClassName(Class<?> testClass) {
|
||||||
String className = testClass.getName();
|
String className = testClass.getName();
|
||||||
int posOfInnerClass = className.lastIndexOf('$');
|
int posOfInnerClass = className.lastIndexOf('$');
|
||||||
|
Loading…
Reference in New Issue
Block a user