【问题标题】:Can not convert from Class<PowerMockRunner> to Class<? extends Runner>无法从 Class<PowerMockRunner> 转换为 Class<?扩展亚军>
【发布时间】:2015-08-19 20:01:10
【问题描述】:

我正在尝试使用 power mockito 编写单元测试用例。

使用注解@RunWith(PowerMockRunner.class) 时出现以下编译错误:-

TypeMismatch: cannot convert from Class<PowerMockRunner> to Class<? extends Runner>

这里是代码 sn-p。使用 junit 4.8.1 和 power mock 1.6.2。

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
public class XXXTest {
    @Test
    public void testOne() {
        if (true)
            System.out.println("Success");
    }
}

【问题讨论】:

  • 你试过 junit 4.11 和 powermock-module-junit4 1.6.0,对我有用!
  • 哈利感谢您抽出宝贵时间。最后我发现了我的错误。我下载并添加了Powermock-Module-Junit4 jar,并没有添加依赖jar Powermock-Module-Junit4-Common.jar。添加通用jar时Powermock-Module-Junit4-Common解决了这个错误。

标签: java unit-testing mockito junit4 powermock


【解决方案1】:

我下载并添加了Powermock-Module-Junit4 jar,并没有添加依赖jar Powermock-Module-Junit4-Common.jar。添加通用jar时Powermock-Module-Junit4-Common解决了这个错误。

谢谢, 瓦苏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 2020-02-10
    • 1970-01-01
    相关资源
    最近更新 更多