我试图模拟最后一个类的静态方法:Files。以身作则。
我读到我必须用户一个mock制造商内联mockito插件,所以我设置它:
我把这个:
mock-maker-inline
在:src/test/Resources/mockito扩展/org.mockito.plugins.MockMaker
然后我模拟了我的类并尝试验证我的模拟是否被调用:
@PrepareForTest(Files.class)
@RunWith(PowerMockRunner.class)
public class StaticFinalMethodTests
{
@InjectMocks
private FileManipulationClass fileManipulationClass;
@Before
public void setUp()
{
PowerMockito.mockStatic(Files.class);
}
@Test
public void fileManipulationTest() throws IOException
{
Mockito.when(Files.exists(Mockito.nullable(Path.class))).thenReturn(false);
Files.exists(getDummyPath());
PowerMockito.verifyStatic(Files.class);
Files.exists(getDummyPath());
}
private Path getDummyPath()
{
return Paths.get("/dummy/path");
}
}
我有一个例外:
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:60)
at com.sun.proxy.$Proxy11.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:232)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:226)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:64)
at org.mockito.Mockito.mock(Mockito.java:1855)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMethodInvocationControl(DefaultMockCreator.java:108)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.doCreateMock(DefaultMockCreator.java:61)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:53)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:40)
at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:62)
at com.example.unitTest.GenericTestWithStatic.lambda$0(GenericTestWithStatic.java:17)
at com.example.unitTest.GenericTestWithStatic$$Lambda$1.00000000104C10B0.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:959)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:591)
at com.example.unitTest.GenericTestWithStatic.initStaticMocks(GenericTestWithStatic.java:17)
at com.example.unitTest.ko.StaticFinalMethodTests.setUp(StaticFinalMethodTests.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:133)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:298)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:218)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:160)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:134)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:136)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:117)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.ClassLoader$CompoundEnumeration@9e7fde3c
at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:94)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:48)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:20)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:18)
at org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine.preLoadPluginLoader(PowerMockitoInjectingAnnotationEngine.java:49)
at org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine.process(PowerMockitoInjectingAnnotationEngine.java:37)
at org.powermock.api.extension.listener.AnnotationEnabler.injectSpiesAndInjectToSetters(AnnotationEnabler.java:61)
at org.powermock.api.extension.listener.AnnotationEnabler.beforeTestMethod(AnnotationEnabler.java:56)
at org.powermock.tests.utils.impl.PowerMockTestNotifierImpl.notifyBeforeTestMethod(PowerMockTestNotifierImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:308)
... 23 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
Java : 1.8
JVM vendor name : IBM Corporation
JVM vendor version : 2.8
JVM name : IBM J9 VM
JVM version : pwa6480sr3fp10-20160720_02 (SR3 FP10)
JVM info : JRE 1.8.0 Windows 10 amd64-64 Compressed References 20160719_312156 (JIT enabled, AOT enabled)
J9VM - R28_Java8_SR3_20160719_1144_B312156
JIT - tr.r14.java_20160629_120284.01
GC - R28_Java8_SR3_20160719_1144_B312156_CMPRSS
J9CL - 20160719_312156
OS name : Windows 10
OS version : 10.0
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:171)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1899)
at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:89)
... 32 more
Caused by: java.lang.IllegalStateException:
Byte Buddy requires retransformation for creating inline mocks. This feature is unavailable on the current VM.
You cannot use this mock maker on this VM
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(InlineByteBuddyMockMaker.java:103)
... 35 more
我在mockito 2.7.22中使用了power mockito 2.0.0
有什么我能做的吗?
回答一个悬而未决的问题永远不会太迟...
我使用JDK 8IBM也有同样的问题。
java.lang.RuntimeException: Invoking the beforeTestMethod method on PowerMock test listener org.powermock.api.extension.listener.AnnotationEnabler@c6c71aa4 failed.
at org.powermock.tests.utils.impl.PowerMockTestNotifierImpl.notifyBeforeTestMethod(PowerMockTestNotifierImpl.java:84)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:308)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:298)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:218)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:160)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:134)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:136)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:117)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
at com.sun.proxy.$Proxy10.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:33)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:250)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:232)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:61)
at org.mockito.Mockito.mock(Mockito.java:1951)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMethodInvocationControl(DefaultMockCreator.java:108)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.doCreateMock(DefaultMockCreator.java:61)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:53)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:40)
at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:181)
at org.powermock.api.extension.listener.AnnotationEnabler.standardInject(AnnotationEnabler.java:98)
at org.powermock.api.extension.listener.AnnotationEnabler.beforeTestMethod(AnnotationEnabler.java:55)
at org.powermock.tests.utils.impl.PowerMockTestNotifierImpl.notifyBeforeTestMethod(PowerMockTestNotifierImpl.java:82)
... 24 more
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.ClassLoader$1@af2e2d5
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:65)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:19)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:16)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:28)
... 37 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:88)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
at java.lang.reflect.Constructor.newInstance(Constructor.java:436)
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:52)
... 42 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker.
It appears as if you are running an incomplete JVM installation that might not support all tooling APIs
Java : 1.8
JVM vendor name : IBM Corporation
JVM vendor version : 2.8
JVM name : IBM J9 VM
JVM version : pwa6480sr1fp10-20150711_01 (SR1 FP10)
JVM info : JRE 1.8.0 Windows 10 Pro amd64-64 Compressed References 20150630_255633 (JIT enabled, AOT enabled)
J9VM - R28_jvm.28_20150630_1742_B255633
JIT - tr.r14.java_20150625_95081.01
GC - R28_jvm.28_20150630_1742_B255633_CMPRSS
J9CL - 20150630_255633
OS name : Windows 10 Pro
OS version : 10.0
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:234)
... 47 more
Caused by: java.lang.IllegalStateException:
Byte Buddy requires retransformation for creating inline mocks. This feature is unavailable on the current VM.
You cannot use this mock maker on this VM
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(InlineByteBuddyMockMaker.java:120)
... 47 more
因此,我无法解释原因和来源,但我决定不再使用IBM JDK,而是下载并配置了JDK Oracle 1.8.0291版。
之后,异常和bug被删除。
THE NVL Maker 是基于吉里吉里 / KAG 开发的新手向电子小说 / 文字冒险游戏制作工具。图形化的意思是拥有图形界面。因此只要你具有一定程度的软件操作常识,比如会做PPT,或者会用Photoshop,用The NVL Maker制作游戏程序对你来说就是很简单的事了。 此外,可以随时通过修改代码的方式来做出自己想要的特殊功能。最大程度地保留了扩展性。
问题内容: 我目前正在研究Mockito框架,并且已经使用Mockito创建了一些测试用例。但后来我读到的不是调用模拟( SomeClass的 的.class)我可以使用和-我需要做的唯一一件事情就是我的注释测试类或使用的方法。 但这不起作用-似乎不会起作用!这是我的2个代码修订-一个使用注释,另一个不使用注释。 我究竟做错了什么? 正如我所说-这项工作很棒。但是以下内容不会: 这是课程: 我想念
问题内容: 在Oracle 10g上,我们需要将视图中的记录插入表中,以支持本身没有sort或ORDER选项的哑客户端应用程序。有什么方法可以控制我们的INSERT语句将记录添加到目标表的顺序? 问题答案: 您 不能 可靠地控制Oracle以何种顺序检索表的行,而不带。 此外,如果没有提示,Oracle将把这些行实际存储在一个有空间的堆表中,该空间可能不在表的末尾!您可能会认为Oracle会按顺序
我们需要使用模拟制作者内联来模拟某些第三方库(例如 Azure SDK)的最终类。 我们使用以下版本的 scalatest 和 mockito: 在我们的Scala应用程序中启用mock-maker-inline后,其他使用trait具有最终方法的测试用例开始失败并出现以下错误: 我们用测试Scala应用程序模拟了这个问题。如果我们禁用mock-maker-inline,那么这个测试用例可以工作。
我想知道是否有任何方法可以隐藏或禁用用户向Google Map Maker提供的自行车道/步道? 我的网站有一个骑行区,当你将地图从Google Earth切换到Google Maps时,会显示大量错误/不准确的地图制作数据。http://www.trailforks.com/riding_areas/cumberland 数据在Map maker上可见。http://goo.gl/Ebnq4 我
一款强大的代码自动生成工具,能够通过设计好的数据库结构,生成多种语言可以直接运行的代码,包含常用流行的开发框架,把日常对表的crud操作代码,自动生成,让开发者更多地关注业务。 提供了大量的特效,供操作选择: pojo 支持常用set, get pojo结构,以及Lombok. mybatis的mapper,支持常用的crud,还支持唯一索引的rud,表与表支持的关联查询:多对一,一对多, 多