如何在 JUnit 5 中模拟静态方法

问题描述 投票:0回答:1

我正在将 JUnit 升级到版本 5,当我运行 JUnit 5 时出现此错误

我在我的pom中使用

<dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
</dependency>

org.powermock.api.mockito.ClassNotPreparedException:

[Ljava.lang.Object;@723ca036 com.xxxxxx.MyClass 类未准备好 用于测试。

我正在使用

@RunWith(JUnitPlatform.class)
作为我的课堂测试符号

我的代码是

PowerMockito.mockStatic(MyClass.class);
when(MyClass.get(anyString()))
    .thenReturn(mock);
junit junit5
1个回答
0
投票

您必须使用ExtendWith。在junit 5中,注释被@RunWith更改为

@ExtendWith(JUnitPlatform.class)

有关如何使用 Extend with 的更多详细信息

© www.soinside.com 2019 - 2024. All rights reserved.