mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-25 11:51:15 +08:00
avoid test case naming conflict between classes
This commit is contained in:
parent
b74b21cae6
commit
65807eece7
@ -28,7 +28,8 @@ public class InvokeVerifier {
|
|||||||
public static InvokeVerifier verify(String mockMethodName) {
|
public static InvokeVerifier verify(String mockMethodName) {
|
||||||
String testClass = Thread.currentThread().getStackTrace()[InvokeRecordUtil.INDEX_OF_TEST_CLASS].getClassName();
|
String testClass = Thread.currentThread().getStackTrace()[InvokeRecordUtil.INDEX_OF_TEST_CLASS].getClassName();
|
||||||
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
||||||
return new InvokeVerifier(InvokeRecordUtil.getInvokeRecord(mockMethodName, testCaseName));
|
String recordIdentify = InvokeRecordUtil.getInvokeIdentify(mockMethodName, testClass, testCaseName);
|
||||||
|
return new InvokeVerifier(InvokeRecordUtil.getInvokeRecord(recordIdentify));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,27 +31,36 @@ public class InvokeRecordUtil {
|
|||||||
String mockMethodName = mockMethodTraceElement.getMethodName();
|
String mockMethodName = mockMethodTraceElement.getMethodName();
|
||||||
String testClass = mockMethodTraceElement.getClassName();
|
String testClass = mockMethodTraceElement.getClassName();
|
||||||
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
String testCaseName = TestableUtil.currentTestCaseName(testClass);
|
||||||
String key = testCaseName + JOINER + mockMethodName;
|
String identify = getInvokeIdentify(mockMethodName, testClass, testCaseName);
|
||||||
List<Object[]> records = getInvokeRecord(mockMethodName, testCaseName);
|
List<Object[]> records = getInvokeRecord(identify);
|
||||||
if (isConstructor) {
|
if (isConstructor) {
|
||||||
records.add(args);
|
records.add(args);
|
||||||
LogUtil.verbose("Mock constructor invoked \"%s\"", key);
|
LogUtil.verbose("Mock constructor invoked \"%s\"", identify);
|
||||||
} else {
|
} else {
|
||||||
records.add(slice(args, 1));
|
records.add(slice(args, 1));
|
||||||
LogUtil.verbose("Mock method invoked \"%s\"", key);
|
LogUtil.verbose("Mock method invoked \"%s\"", identify);
|
||||||
}
|
}
|
||||||
INVOKE_RECORDS.put(key, records);
|
INVOKE_RECORDS.put(identify, records);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get identify key for mock invocation record
|
||||||
|
* @param mockMethodName mock method name
|
||||||
|
* @param testClass test class name
|
||||||
|
* @param testCaseName test case name
|
||||||
|
* @return identify key
|
||||||
|
*/
|
||||||
|
public static String getInvokeIdentify(String mockMethodName, String testClass, String testCaseName) {
|
||||||
|
return testClass + JOINER + testCaseName + JOINER + mockMethodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get mock method invoke count
|
* Get mock method invoke count
|
||||||
* @param mockMethodName mock method name
|
* @param identify key of invocation record
|
||||||
* @param testCaseName test case name
|
|
||||||
* @return parameters used when specified method invoked in specified test case
|
* @return parameters used when specified method invoked in specified test case
|
||||||
*/
|
*/
|
||||||
public static List<Object[]> getInvokeRecord(String mockMethodName, String testCaseName) {
|
public static List<Object[]> getInvokeRecord(String identify) {
|
||||||
String key = testCaseName + JOINER + mockMethodName;
|
List<Object[]> records = INVOKE_RECORDS.get(identify);
|
||||||
List<Object[]> records = INVOKE_RECORDS.get(key);
|
|
||||||
return (records == null) ? new LinkedList<Object[]>() : records;
|
return (records == null) ? new LinkedList<Object[]>() : records;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user