我正在尝试使用PowerMockito模拟类的所有实例,类似于Mock all instances of a class中的帖子。
在代码中没有任何模拟,仅添加Power Mock注释会导致错误。基本上,我将这些添加到了课程的开头:
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyClass.class)
@PowerMockIgnore("javax.management.*")
除此之外,尽管没有任何与Mockito相关的代码行,但我从春季开始就收到了此异常:
java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean' defined in URL [jar:file:<path>/MyClass.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.myPackage.MyClass]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
问题是,仅添加这些注释并且测试开始失败时会发生什么。