Why do I get an error "package org.mockito.runners does not exist"?

It looks like Gradle is not doing it's job. Manually adding the jars may fixed the problem. How to Download and Install jar go here .

and for download mockito use this link

https://mvnrepository.com/artifact/org.mockito/mockito-core/1.10.19


As stated in Baeldung's article, starting from Mockito version 2.2.20, the package for MockitoJUnitRunner has changed. So change :

import org.mockito.runners.MockitoJUnitRunner;

To :

import org.mockito.junit.MockitoJUnitRunner;

As usual, you have to import the mockito-core library in your build.gradle :

dependencies {
    testImplementation 'org.mockito:mockito-core:4.2.0'
}

As a side note, you will also need to change import for Matchers if you use them. For instance :

From :

import static org.mockito.Matchers.any;

To :

import static org.mockito.Mockito.any;