cost 390 ms
Mocking class 返回 NULL 即使在手动设置值之后 - Mocking class return NULL even after set the value manually

我是单元测试的新手,并尝试了解 mocking 的工作原理。 我得到了如下代码,其中我使用PowerMockRunner模拟PdRequest.class 。 但是,它为所有变量返回Null 。 我也尝试手动设置值,但它是一样的。 我有什么想念的吗? 如果我只创建new PdRequest()并手动 ...

Log.w() 抛出 `java.lang.RuntimeException: Stub.` 尽管有 `@PrepareForTest(Log.class)` - Log.w() throws `java.lang.RuntimeException: Stub!` despite `@PrepareForTest(Log.class)`

我正在尝试为间接使用Log.w() 。 当我第一次遇到java.lang.RuntimeException: Stub! 结果,我很快发现这是 Android 开发中的一个众所周知的问题,我可以使用 mocking: 在我的应用程序的build.gradle中具有以下dependencies {} ...

org.jetbrains.annotations @NotNull 在模拟私有方法时与 Mockito 交互 - org.jetbrains.annotations @NotNull interfare with Mockito when mock a private method

我试图通过将 mockito 匹配器“eq”传递给它的参数来使用 powermock 模拟我的服务的私有方法。 其中一个参数使用来自 jetbrains 的 @NotNull 装饰器进行注释。 当我运行测试时,出现以下错误: java.lang.IllegalArgumentException:Y ...

java.lang.IllegalStateException:在 org.easymock.getControlForLastCall (EasyMock.java:559) 上没有最后一次调用可用的模拟 - java.lang.IllegalStateException: no last call on a mock available at org.easymock.getControlForLastCall (EasyMock.java:559)

我正在尝试使用 PowerMock 模拟 static 非最终方法。 我的测试 class 注释看起来像: 我的测试看起来像这样: 我收到一条错误消息: 我需要运行器为SpringJUnit4ClassicRunner ,因为我需要先加载ApplicationContext ,然后模拟所需的类。 我 ...

Mocking 一个 function 没有包含 CriteriaBuilder 的参数是否可能? - Mocking a function without argument containing CriteriaBuilder is it possible?

我认为不可能模拟标准构建器的原因是因为它只响应在 postgres 中创建的数据库。 如果不是这种情况,那么如何解决此错误(如下所示)。 class MessageRest class 消息存储库 class MessageRestTest 得到的错误是 NullpointerExcepti ...

与 PowerMockRunner 一起运行时,在单元测试中使用 List.of() 失败并出现 IncompatibleClassChangeError - Using List.of() in unit tests fails with IncompatibleClassChangeError when run with PowerMockRunner

在使用PowerMockRunner运行时,在 Junit 测试中使用List.of()会失败。 当使用MockitoJUnitRunner运行时,这非常有效。 当我们执行下面的代码 带有错误消息的IncompatibleClassChangeError java.lang.Incompatibl ...

如何使用 EasyMock 和 PowerMock 模拟构造函数内部初始化的最终变量? - How to mock final variable initialized inside constructor ,using EasyMock and PowerMock?

下面提到的代码是实现类,需要模拟 junit 内部的最终变量。并设置所需的值。 测试方法 运行测试时出现错误 org.powermock.reflect.exceptions.MethodNotFoundException:在类 com.xx.xx.xx.xx.XyzInterceptor ...

使用 PowerMock 模拟注入属性时的 NullPointer - NullPointer when mock an inject attribute using PowerMock

我正在使用 PowerMock 测试一个类,当要模拟的字段为空时,我得到空指针异常。 我在嘲笑两个领域,一个是高尔夫,另一个是探戈。 高尔夫被嘲笑得很好,但 NullPointer 恰好发生在高尔夫身上。 PS:为了降低复杂度,我将代码归结为它可能看起来不需要PowerMock,但实际上它是需要 ...

引起:java.lang.RuntimeException:java.io.IOException:无效的常量类型:18 - Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18

我正在将旧的遗留应用程序从 Log4j1.x 迁移到 2.x,并在运行测试用例时遇到错误。 我已经通过链接: Powermock - java.lang.IllegalStateException: Failed to transform class , but no lick 下面是maven ...

Junit 5 使用 mockConstruction().withSetting().useConstructor() 而不是 PowerMock.whenNew().withArguments() - Junit 5 use mockConstruction().withSetting().useConstructor() instead of PowerMock.whenNew().withArguments()

现在我想使用 Junit 5 + Mockito 4.x 版本 + Mockito-inline 4.x 版本而不是 Junit 4 + PowerMock 2.0.9 因为 Junit 5 不支持 PowerMock 并且 Mockito-inline 可以模拟静态,看起来它不再需要 Power ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM