【发布时间】:2011-07-05 17:42:11
【问题描述】:
我使用 ASM 为 javaagent 实现了 ClassFileTransformer。因为它有一些bug,所以我想为它写一个JUnit测试用例。我该怎么做?
使用我认为的伪代码:
// Have a test class as subject
public static class Subject {
public void doSomething(){...}
}
// Manually load and transform the subject
...?
// Normally execute some now transformed methods of the subject
new Subject().doSomething();
// Check the result of the call (i.e. whether the correct attached methods were called)
Assert.assertTrue(MyClassFileTransformer.wasCalled());
现在的问题是:我如何手动加载和转换主题并让 JVM/Classloader 使用我操纵的版本?还是我完全错过了什么?
【问题讨论】:
标签: java instrumentation javaagents