public class HuronClassloader extends URLClassLoader {
public HuronClassloader(Logger logger) {
super(new URL[0]);
this.logger = logger;
}
public void doLogic() throws ClasspathFormattingException {
// logic go heer
}
//如何使用JMockit测试doLogic方法?
答案 0 :(得分:0)
你可以尝试如下;初始化测试类时,@ Injectable会自动将模拟Logger对象注入构造函数。
import mockit.Injectable;
import mockit.Tested;
...
@Tested
HuronClassloader loader;
@Injectable
Logger logger;
@Test
public void testSomeMethod() {
//Optionally you can set expectation on your mock
new Expectations() {{
logger.someMethod(); result = ...;
}};
loader.doLogic();
}