Я хочу сделать некоторые тесты, используя инструментальные в Android (мне нужно получить AppContext, чтобы получить каталог для создания моего тестового DB).
Но у меня была ошибка: никаких инструментов зарегистрировано! Необходимо работать в соответствии с инструментами регистрации. 'com.diegogaona.cocktailhype.data.repository.tagrepositorydbtest': < /p>
Код: Выделить всё
1. No runnable methods
at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
at org.junit.runners.ParentRunner.(ParentRunner.java:92)
at org.junit.runners.BlockJUnit4ClassRunner.(BlockJUnit4ClassRunner.java:74)
< /code>
Мой код:
мой тестовый класс в Commontest: < /p>
@file:OptIn(ExperimentalCoroutinesApi::class, ExperimentalSerializationApi::class)
package com.diegogaona.cocktailhype.data.repository
import com.diegogaona.cocktailhype.data.local.CouchbaseManager
import com.diegogaona.cocktailhype.data.local.couchbaseLocalConfigTest
import com.diegogaona.cocktailhype.di.LogWrapper
import com.diegogaona.cocktailhype.domain.model.Colors
import com.diegogaona.cocktailhype.domain.model.TagToSave
import com.diegogaona.cocktailhype.domain.model.Translation
import com.diegogaona.cocktailhype.domain.repository.IDatabaseManager
import io.kotest.core.spec.style.FunSpec
import io.kotest.koin.KoinExtension
import kotbase.Database
import kotbase.Collection
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.ExperimentalSerializationApi
import org.junit.runner.RunWith
import org.koin.dsl.module
import org.koin.test.KoinTest
import org.koin.test.inject
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.fail
import org.robolectric.RobolectricTestRunner
val testModule = module {
val logger = object : LogWrapper {
override fun d(message: String, tag: String?) {
println("Debug: $message | Tag: $tag")
}
override fun i(message: String, tag: String?) {
println("Info: $message | Tag: $tag")
}
override fun w(message: String, tag: String?) {
println("W: $message | Tag: $tag")
}
override fun e(message: String, tag: String?, throwable: Throwable?) {
println("Error: $message, Throwable: $throwable")
}
}
single {
CouchbaseManager(couchbaseLocalConfigTest)
}
single { logger }
single { TagRepositoryDb(databaseManager = get(), logger = get()) }
}
@RunWith(RobolectricTestRunner::class)
class TagRepositoryDbTest : FunSpec(), KoinTest {
override fun extensions() = listOf(KoinExtension(testModule))
val tagRepository by inject()
val databaseManager by inject()
init {
test("save and get operations should work correctly") {
runBlocking {
val tagToSave = TagToSave(
name = Translation(txt = "IntegrationTestTag"),
colors = Colors(high = "#FF5733", bg = "#C70039")
)
val saveResult = tagRepository.save(tagToSave)
assertTrue(saveResult.isSuccess, "Tag should be saved successfully.")
delay(300)
val tagFlow = tagRepository.getMany("IntegrationTestTag", useFts = false)
val tags = tagFlow.first()
assertTrue(
tags.isNotEmpty(),
"There should be at least one tag matching the search term."
)
val savedTag = tags.first() ?: fail("Saved tag should not be null")
val getResult = tagRepository.get(savedTag.id)
getResult?.let { assertTrue(it.isSuccess, "get() should return the tag successfully.") }
val retrievedTag = getResult?.getOrNull() ?: fail("Retrieved tag is null")
assertEquals(savedTag.id, retrievedTag.id)
assertEquals("IntegrationTestTag", retrievedTag.name.txt)
}
} // More tests....
< /code>
В моем каталоге AndroidStrumentEdtest я имею: < /p>
package com.diegogaona.cocktailhype
import android.app.Instrumentation
import android.content.Context
import androidx.test.platform.app.InstrumentationRegistry
import br.com.colman.kotest.KotestRunnerAndroid
import org.junit.BeforeClass
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
lateinit var testAppContext: Context
@RunWith(RobolectricTestRunner::class)
class TestSetup {
companion object {
private lateinit var instrumentation: Instrumentation
@BeforeClass
@JvmStatic
fun setupContext() {
instrumentation = InstrumentationRegistry.getInstrumentation()
testAppContext = instrumentation.targetContext
}
}
}
actual fun getDatabasePathTest(): String {
TestSetup.setupContext()
return testAppContext.filesDir.path
}
< /code>
Почему я получаю эту ошибку? Почему он не распознает мои тесты? < /P>
Заранее! Необходимо работать в соответствии с прибором регистрации. попробовал JUNIT 4 и 5 и другие конфигурации.
Подробнее здесь: https://stackoverflow.com/questions/794 ... mp-project
Мобильная версия