要修复测试用例,我需要确定是否从特定的调用程序函数中调用了该函数。我负担不起添加布尔值参数,因为它会破坏定义的接口。怎么办呢?
这是我想要实现的。在这里,我无法更改operation()的参数,因为它是接口实现。
operation() { if not called from performancetest() method do expensive bookkeeping operation ... }
你可以试试
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace(); StackTraceElement e = stacktrace[2];//maybe this number needs to be corrected String methodName = e.getMethodName();