hzdavid / jmockit.cn

JMockit中文网(jmockit.cn)上所有讲述的测试示例源代码
36 stars 15 forks source link

怎么mock Thread.sleep方法 #8

Closed xiongshanliang closed 5 years ago

xiongshanliang commented 5 years ago

怎么mock,Thread.sleep方法,让他不用等待,我看例子里有mock native方法的,但是有个 @BeforeClass
// 加载AnOrdinaryClass类的native方法的native实现
public static void loadNative() throws Throwable {
JNITools.loadNative();
}

不知道加载Thread类的native方法实现怎么写

xiongshanliang commented 5 years ago

已找到解决方法: @BeforeClass public static void loadNative() throws Throwable { Class c = Thread.class; Method registerNatives = c.getDeclaredMethod("registerNatives"); registerNatives.setAccessible(true); registerNatives.invoke(c); }