我有一些测试类需要验证是否调用了GLFW函数。但是当我想在IntelliJ中执行所有测试时,就会出现以下错误:
Native Library lwjgl.dll already loaded in another classloader
我使用Powermock来验证静态方法是否被调用:
@RunWith(PowerMockRunner.class)
@PrepareForTest({GLFW.class})
public class GlfwWindowImplTest {
// ...
@Test
public void update_swapsBufferAndPollsEvents() {
GlfwWindowImpl target = new GlfwWindowImpl(1L);
mockStatic(GLFW.class);
target.update();
verifyStatic();
GLFW.glfwSwapBuffers(1L);
verifyStatic();
GLFW.glfwPollEvents();
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest({GLFW.class})
public class GlfwWindowSystemImplTest {
// ...
@Test(expected = GlfwInitializeException.class)
public void initialize_throwsExceptionIfGlfwInitFails() {
GlfwWindowSystemImpl target = new GlfwWindowSystemImpl();
mockStatic(GLFW.class);
when(GLFW.glfwInit()).thenReturn(GL_FALSE);
target.initialize();
}
}
@PrepareForTest({GLFW.class})
...那么你需要做什么不同的事情呢?谢谢。 - Nova