找不到Powermock junit5和mockito2.x不能运行RunnerTestSuiteChunker [英] Powermock junit5 and mockito2.x not working RunnerTestSuiteChunker not found

查看:439
本文介绍了找不到Powermock junit5和mockito2.x不能运行RunnerTestSuiteChunker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Mokito 2.0,Junit 5和具有maven-surefire-plugin的Junit 4运行powermock.

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

测试类看起来像

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看起来像

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>

出现错误:

[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 

推荐答案

我成功地通过将Mockito-core升级到2.23.4来使示例运行了

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

这篇关于找不到Powermock junit5和mockito2.x不能运行RunnerTestSuiteChunker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆