Issue
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
Solution
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.
Answered By - M. Deinum
Answer Checked By - Gilberto Lyons (JavaFixing Admin)