I am developing new todo app but when I run my test I am getting following warning and errors
com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.example.todo.TodoRoomRepositoryTest [Robolectric] WARN: Android SDK 29 requires Java 9 (have Java 8). Tests won't be run on SDK 29 unless explicitly requested. [Robolectric] WARN: Android SDK 30 requires Java 9 (have Java 8). Tests won't be run on SDK 30 unless explicitly requested. WARNING: No manifest file found at .\AndroidManifest.xml. Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE). No such manifest file: .\AndroidManifest.xml
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
I have followed following stackoverflow it did not solve my issue and I have done all suggested answers
@RunWith(AndroidJUnit4::class)
@Config(sdk = [Build.VERSION_CODES.P])
class TodoRoomRepositoryTest {
@get:Rule
val testRule = InstantTaskExecutorRule()
val now = System.currentTimeMillis()
val day = 1000 * 60 * 60 * 24
private lateinit var db:TodoRoomDatabase
@Before
fun setUp(){
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(context, TodoRoomDatabase::class.java)
.allowMainThreadQueries()
.build()
}
@Test
fun test_getUpcomingTodoCountEmpty(){
val dao = spy(db.todoDao())
val repo = TodoRoomRepository(dao)
val expected = 0
val actual = repo.getUpcomingTodosCount().test().value()
assertEquals(expected, actual)
verify(dao).getDateCount(any())
}
@After
fun tearDown(){
db.close()
}
}
below my app.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
I am developing new todo app but when I run my test I am getting following warning and errors
com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.example.todo.TodoRoomRepositoryTest [Robolectric] WARN: Android SDK 29 requires Java 9 (have Java 8). Tests won't be run on SDK 29 unless explicitly requested. [Robolectric] WARN: Android SDK 30 requires Java 9 (have Java 8). Tests won't be run on SDK 30 unless explicitly requested. WARNING: No manifest file found at .\AndroidManifest.xml. Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE). No such manifest file: .\AndroidManifest.xml
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
I have followed following stackoverflow it did not solve my issue and I have done all suggested answers
below my Testing class
import android.content.Context import android.os.Build import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.room.Room import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.todo.data.TodoRepository import com.example.todo.data.TodoRoomDatabase import com.example.todo.data.TodoRoomRepository import com.jraska.livedata.test import org.junit.After import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.any import org.mockito.kotlin.spy import org.mockito.kotlin.verify import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class) @Config(sdk = [Build.VERSION_CODES.P]) class TodoRoomRepositoryTest {
}
below my app.gradle
plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'kotlin-android-extensions' }
android { compileSdkVersion 30 buildToolsVersion "30.0.2"
}
dependencies {
def archLifecycleVersion = '2.2.0'
// Lifecycle components implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion" //noinspection LifecycleAnnotationProcessorWithJava8 kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion" androidTestImplementation "androidx.arch.core:core-testing:$archLifecycleVersion"
// ViewModel Kotlin support implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
// Coroutines implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3"
}