I am getting the following error when I am trying to run my mock test in Android
`Execution failed for task ':app:kaptGenerateStubsDebugUnitTestKotlin'.
Error while evaluating property 'filteredArgumentsMap' of task ':app:kaptGenerateStubsDebugUnitTestKotlin'. Could not resolve all files for configuration ':app:debugUnitTestCompileClasspath'. > Could not find org.mockito.kotlin:mockito-kotlin:2.2.0. Required by: project :app`
Here is my gradle files
build.gradle(:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
id 'kotlin-android'
}
android {
namespace 'com.example.resturants'
compileSdk 34
defaultConfig {
applicationId "com.example.resturants"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
dataBinding {
enabled = true
}
kapt {
generateStubs = true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
//navigation
def navigation_version = "2.7.5"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
//Add viewmodel library
def lifecycle_version = "2.7.0-rc01"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
//Add coroutine library
def coroutine_version = '1.4.2'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutine_version"
// retrofit
def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// Location Services
def location_version = "21.0.1"
implementation "com.google.android.gms:play-services-location:$location_version"
//hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
//Glide
def glide_version = "4.16.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
//core:arch:testing
def core_arch_test_version = "2.2.0"
testImplementation "androidx.arch.core:core-testing:$core_arch_test_version"
androidTestImplementation "androidx.arch.core:core-testing:$core_arch_test_version"
//mock webserver
def mock_web_server_version = "4.12.0"
testImplementation "com.squareup.okhttp3:mockwebserver:$mock_web_server_version"
//mockito
def mockito_version = "3.6.0"
def mockito_kotlin_version = "2.2.0"
testImplementation "org.mockito:mockito-core:$mockito_version"
testImplementation "org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"
//turbine
def turbine_version = "1.0.0"
testImplementation "app.cash.turbine:turbine:$turbine_version"
}
build.gradle(Project)
buildscript {
ext.kotlin_version = "1.7.20"
ext.hilt_version = "2.42"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I want to run my test case but I got stucked for this issue. May anyone please help me on it
Error seems to be that it can't find the dependency
org.mockito.kotlin:mockito-kotlin:2.2.0:The mockito package was renamed to
org.mockito.kotlinonly on version 2.2.7.So you have two options:
build.gradleto:Version list for
com.nhaarman.mockitokotlin2:mockito-kotlin: https://search.maven.org/artifact/com.nhaarman.mockitokotlin2/mockito-kotlinVersion list for
org.mockito.kotlin:mockito-kotlin: https://search.maven.org/artifact/org.mockito.kotlin/mockito-kotlin