Raj
Raj

Reputation: 4089

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.

I am able to run the main application. So, I am guessing that it is not a JRE/JDK problem.

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.)

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

Upvotes: 0

Views: 22166

Answers (1)

M. Deinum
M. Deinum

Reputation: 125048

First add the dependency to Mockito to you project, second import the class from the proper location.

<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. Currently it will only slow down your test runs.

Upvotes: 4

Related Questions