Closed sbabcoc closed 2 years ago
Unsurprisingly, the Executable class cannot be instrumented. I think I can do this by instrumenting the FrameworkMethod class instead. This class has getAnnotations()
and getAnnotation(...)
methods that could be overridden to return cached values instead of forwarding the calls to their respective intercepted methods.
Resolved by #119
Currently, the
MutableTest
class uses reflection to access the list of declared annotations of the Java Executable class. The objective is to replace the standard Test annotation with a mutable proxy to enable overriding the value of thetimeout
field. Reflective access to the required private field of the Executable class is no longer legal. This deprecated functionality can be permitted with the--illegal-access=permit
option, but this is definitely sub-optimal. This illegal implementation should be replaced with supported functionality implemented with the Advice feature of Byte Buddy.An example of this sort of implementation can be found here. A comprehensive guide can be found here. To intercept private methods and access private fields, check this. The MemberSubstitution unit tests can be found here. Example of attaching advice to a core Java class is found here.
The theory is that we can intercept the execution of
Executable.declaredAnnotations()
on exit, replacing the standard Test annotation with an instance of MutableTest. The code in MockMethodAdvice of Mockito is seemingly applicable to this scenario.