yenk
yenk

Reputation: 217

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);

Upvotes: 1

Views: 10602

Answers (1)

Chiranjeevi C A
Chiranjeevi C A

Reputation: 1

You have to use ExtendWith. In junit 5 the annotation gets @RunWith changed to

@ExtendWith(JUnitPlatform.class)

Further details on how to use Extend with

Upvotes: 0

Related Questions