'How to mock a static method in JUnit 5
I am upgrading my JUnit to version 5 and I get this error when I run the JUnit 5
I am using in my 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 The class com.xxxxxx.MyClass not prepared for test.
I am using @RunWith(JUnitPlatform.class) for my class test notation
My code is
PowerMockito.mockStatic(MyClass.class);
when(MyClass.get(anyString()))
.thenReturn(mock);
Solution 1:[1]
You have to use ExtendWith. In junit 5 the annotation gets @RunWith changed to
@ExtendWith(JUnitPlatform.class)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chiranjeevi C A |
