Unable to import mockito in Eclipse - disappeared immediately

Martin picture Martin · Feb 27, 2015 · Viewed 10.6k times · Source

I am trying to do a mock test of my code with mockito. In my POM.xml, the following dependency is stated as below.

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.9.5</version>
</dependency>

However, when I am trying to import the mockito as below, it disappeared immediately and I cannot do anything with it:

import static org.mockito.Mockito.*;

I don't know if there is anything missing in my Eclipse or not. Is there any suggestion so that I can fix it?

"The import org.mockito cannot be resolved" just appeared on the error box.

Answer

Akshay Chopra picture Akshay Chopra · Jan 14, 2020

I made a very silly mistake. The Junit test cases that I was writing were placed under src/main instead of src/test folder. Hence, even the dependency was added in the pom.xml file, it was saying it cannot be resolved. Just make sure your .java file for Junit test cases is under src/test/