lukegjpotter
lukegjpotter

Reputation: 251

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

In Build Path

My Code File is showing the following message:

cannot resolve Mockito

I have another project, setup in exactly the same way and it is working fine.

Please help me out guys, Luke.

Upvotes: 1

Views: 26989

Answers (4)

Dinushika Rathnayake
Dinushika Rathnayake

Reputation: 419

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.

Upvotes: 0

Joseph
Joseph

Reputation: 6031

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

Upvotes: 2

nnedoklanov
nnedoklanov

Reputation: 321

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 enter image description here

This will then result in the following hint: enter image description here

Upvotes: 2

user6011162
user6011162

Reputation:

Use with a static import:

import static org.mockito.Mockito.when;   ...or...
import static org.mockito.Mockito.*; 

Upvotes: 5

Related Questions