简体   繁体   中英

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:

无法解析 Mockito

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

Please help me out guys, Luke.

Use with a static import:

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

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在此处输入图片说明

This will then result in the following hint: 在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM