PowerMockRunner尚未被识别,但所有依赖项都已到位

时间:2018-03-25 22:05:34

标签: java maven mockito powermock

在我的单元测试中,PowerMockRunner尚未被识别,尽管我在我的pom中需要所有依赖项,并且下载了所有必需的jar。我试图测试静态方法。我一直收到错误aStr "Type mismatch: cannot convert from Class<PowerMockRunner> to Class<? extends Runner>"。为什么现在认可PowerMockRunner?我很确定我的所有依赖项都已添加。我使用junit4。这是我的pom文件:

注意:这不是重复的帖子。我的问题承认,为了运行PowerMock需要某些依赖项,但是这个特殊问题询问为什么在添加了所有这些依赖项之后,仍然无法识别PowerMockRunner.class。

@RunWith(PowerMockRunner.class)

这是我的简单测试:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.vismark</groupId>
    <artifactId>TestingTraining</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>TestingTraining</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.6.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.6.4</version>
            <scope>test</scope>
        </dependency>


    </dependencies>
</project>

1 个答案:

答案 0 :(得分:0)

尝试添加powermock-module-junit4-common

<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-junit4-common</artifactId>
    <version>1.6.4</version>
</dependency>