vendredi 26 mars 2021

: Android SDK 30 requires Java 9 (have Java 8). Tests won't be run on SDK 30 unless explicitly requested.?

I am developing android todo app but when I run the project I am getting following error and warnings 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 answer Does Robolectric require Java 9?

but it did not solve my issue below my test class in kotlin

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 {

    @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()
    }

}

Aucun commentaire:

Enregistrer un commentaire