'Mocking Statics with Mockito

I have the following declaration in my test file and the first of these two lines is failing when I run my tests.

@BeforeAll
public static void beforeAll() {
    loggerFactoryMockedStatic = mockStatic(LoggerFactory.class);
    loggerFactoryMockedStatic.when(() -> LoggerFactory.getLogger(PipelineExecutionService.class))
            .thenReturn(logger);
}

The error I get is this:

org.mockito.exceptions.base.MockitoException: 
The used MockMaker SubclassByteBuddyMockMaker does not support 
the creation of static mocks
Mockito's inline mock maker supports static mocks based on the Instrumentation API.
You can simply enable this mock mode, by placing the 'mockito-inline' artifact where 
you are currently using 'mockito-core'.
Note that Mockito's inline mock maker is not supported on Android.

So, I changed part of my POM file from

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <scope>test</scope>
    </dependency>

to

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-inline</artifactId>
        <scope>test</scope>
    </dependency>

But, after running my tests I still get this error. Any idea why this might be?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source