'The import org.mockito.Mock cannot be found
I am experiencing a problem I hope you can help with.
I want to use Mockito in my Spring Boot w/Gradle project, but STS cannot resolve the dependancy.
I have the following in my build.gradle
file;
repositories { jcenter() }
dependencies { testCompile('org.mockito:mockito-core:1.+') }
When I do a ./gradlew --info build
I can see that it is resolving Mockito:
Resolved versions: {org.mockito:mockito-core=1.+}
Using version '1.+' for dependency 'org.mockito:mockito-core:1.+'
Using version '1.+' for dependency 'org.mockito:mockito-core:1.10.19'
After a ./gradlew cleanEclipse eclipse
it is in my STS Project's Build Path
My Code File is showing the following message:
I have another project, setup in exactly the same way and it is working fine.
Please help me out guys, Luke.
Solution 1:[1]
Use with a static import:
import static org.mockito.Mockito.when; ...or...
import static org.mockito.Mockito.*;
Solution 2:[2]
To add to @Harshad's response, you can make your life easier and let Eclipse handle the static imports by adding the mockito methods to your favorite imports
Solution 3:[3]
Add the dependencies with androidTestImplementation "org.mockito:mockito-core:2.28.2"
instead of the testImplementation "org.mockito:mockito-core:2.28.2"
The dependencies added with androidTestImplementation
will be available in:
app\src\androidTest
The dependencies added with testImplementation
will only be available in the android test
folder available on:
app\src\test
Solution 4:[4]
Add testCompile('org.mockito:mockito-core:3.1.0')
dependency to build.gradle and then download sources works for me in Netbeans IDE. Version number can be different.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | nnedoklanov |
Solution 3 | Joseph |
Solution 4 | Dinushika Rathnayake |