Powermock junit5 and mockito2.x not working RunnerTestSuiteChunker not found

16,326

I managed to get the example running simply by upgrading mockito-core to 2.23.4

Share:
16,326

Related videos on Youtube

Sumeet Kumar Yadav
Author by

Sumeet Kumar Yadav

I'm an avid follower of technology and a developer by trade. Technologies : Java Node.js MongoDB Spring Redis Azure AWS Docker Microservices

Updated on June 04, 2022

Comments

  • Sumeet Kumar Yadav
    Sumeet Kumar Yadav almost 2 years

    I am running powermock with mokito 2.0 , Junit 5 and for Junit 4 having maven-surefire-plugin .

    Test class looks like

    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.powermock.api.mockito.PowerMockito;
    import org.powermock.core.classloader.annotations.PowerMockIgnore;
    import org.powermock.core.classloader.annotations.PrepareForTest;
    import org.powermock.modules.junit4.PowerMockRunner;
    
    import static org.mockito.Mockito.*;
    
    
    @PrepareForTest(EnvironmentUtils.class)
    @RunWith(PowerMockRunner.class)
    public class RuleControllerTest {       
    
            @Before
            public void setup() {           
                PowerMockito.mockStatic(EnvironmentUtils.class);
            }   
    
    
            @Test
            public void test_rule_create_rule() throws IOException {
                when(EnvironmentUtils.isCF()).thenReturn(true);
    
            }
    }
    

    POM.xml looks like

    <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.8.9</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.4.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
                <version>5.4.2</version>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.4.2</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>2.0.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-api-mockito2</artifactId>
                <version>2.0.2</version>
                <scope>test</scope>
            </dependency>
    
    
    
    <build>
            <plugins>
                <plugin>
                    <!-- specify JDK for sonar-pmd-plugin -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version><!--$NO-MVN-MAN-VER$ -->
                    <configuration>
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <testSource>1.8</testSource>
                        <testTarget>1.8</testTarget>
                    </configuration>
                </plugin>
    
                <plugin>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <configuration>
                        <targetJdk>${java.version}</targetJdk>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
            </plugins>
        </build>
    

    Getting error :

    [ERROR] initializationError  Time elapsed: 0.008 s  <<< ERROR!
    java.lang.NoClassDefFoundError: org/powermock/tests/utils/RunnerTestSuiteChunker
    Caused by: java.lang.ClassNotFoundException: org.powermock.tests.utils.RunnerTestSuiteChunker 
    
  • Sumeet Kumar Yadav
    Sumeet Kumar Yadav almost 5 years
    can you share your pom.xml ( version of junit , mockito , powermock )
  • Lesiak
    Lesiak almost 5 years
    Same as yours, I only updated mockito-core. (Note: I had another method missing: MockitoFramework.getPlugins)