简体   繁体   English

错误:java:找不到符号符号:类 MockitoJUnitRunner

[英]Error: java: cannot find symbol symbol: class MockitoJUnitRunner

I am starting a fresh Dropwizard project and I am not able to use MockitoJUnitRunner to run tests.我正在开始一个新的 Dropwizard 项目,但我无法使用MockitoJUnitRunner运行测试。

I am able to run the main application.我能够运行主应用程序。 So, I am guessing that it is not a JRE/JDK problem.所以,我猜这不是 JRE/JDK 问题。

Here are a few files from my project:以下是我项目中的一些文件:

pom.xml

<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
</dependency>

FooTest.java (For the sake of simplicity, I removed logic.) FooTest.java (为了简单起见,我删除了逻辑。)

import org.junit.Test;

import org.junit.runner.RunWith;

@RunWith(MockitoJUnitRunner.class)
class FooTest {
  @Test
  public void testSout() {
    System.out.println("This tests works.");
  }
}

I am getting the following error.我收到以下错误。

Error:(20, 10) java: cannot find symbol symbol: class MockitoJUnitRunner错误:(20, 10) java:找不到符号符号:类 MockitoJUnitRunner

First add the dependency to Mockito to you project, second import the class from the proper location.首先将Mockito的依赖项添加到您的项目中,然后从适当的位置导入类。

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

In your class do the proper import.在你的课堂上做适当的导入。

import org.mockito.junit.MockitoJUnitRunner;

NOTE: Your code doesn't really use any of the Mockito annotations like @Mock or @Spy so not sure why you even want to run it with the special mockito runner.注意:您的代码并没有真正使用任何 Mockito 注释,如@Mock@Spy所以不确定为什么您甚至想用特殊的 mockito runner 运行它。 Currently it will only slow down your test runs.目前它只会减慢您的测试运行速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM