You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to do some tests using Instrumented in Android (I need to get the appContext, to get the directory to create my test db).
But I was having the error: No instrumentation registered! Must run under a registering instrumentation.
Now, with Kotest, your extension and Roboeletric, I can make Android Studio recognize my class to test as Instrumented test, but now I have the error:
basic:
Invalid test class 'com.diegogaona.cocktailhype.data.repository.TagRepositoryDbTest':
1. No runnable methods
at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:92)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:74)
My code is:
My test class in commonTest:
@file:OptIn(ExperimentalCoroutinesApi::class, ExperimentalSerializationApi::class)
packagecom.diegogaona.cocktailhype.data.repositoryimportcom.diegogaona.cocktailhype.data.local.CouchbaseManagerimportcom.diegogaona.cocktailhype.data.local.couchbaseLocalConfigTestimportcom.diegogaona.cocktailhype.di.LogWrapperimportcom.diegogaona.cocktailhype.domain.model.Colorsimportcom.diegogaona.cocktailhype.domain.model.TagToSaveimportcom.diegogaona.cocktailhype.domain.model.Translationimportcom.diegogaona.cocktailhype.domain.repository.IDatabaseManagerimportio.kotest.core.spec.style.FunSpecimportio.kotest.koin.KoinExtensionimportkotbase.Databaseimportkotbase.Collectionimportkotlinx.coroutines.ExperimentalCoroutinesApiimportkotlinx.coroutines.delayimportkotlinx.coroutines.flow.firstimportkotlinx.coroutines.runBlockingimportkotlinx.serialization.ExperimentalSerializationApiimportorg.junit.runner.RunWithimportorg.koin.dsl.moduleimportorg.koin.test.KoinTestimportorg.koin.test.injectimportkotlin.test.assertEqualsimportkotlin.test.assertTrueimportkotlin.test.failimportorg.robolectric.RobolectricTestRunnerval testModule = module {
val logger =object:LogWrapper {
overridefund(message:String, tag:String?) {
println("Debug: $message | Tag: $tag")
}
overridefuni(message:String, tag:String?) {
println("Info: $message | Tag: $tag")
}
overridefunw(message:String, tag:String?) {
println("W: $message | Tag: $tag")
}
overridefune(message:String, tag:String?, throwable:Throwable?) {
println("Error: $message, Throwable: $throwable")
}
}
single<IDatabaseManager<Database, Collection>> {
CouchbaseManager(couchbaseLocalConfigTest)
}
single<LogWrapper> { logger }
single<ITagRepository> { TagRepositoryDb(databaseManager = get(), logger = get()) }
}
@RunWith(RobolectricTestRunner::class)
classTagRepositoryDbTest : FunSpec(), KoinTest {
overridefunextensions() =listOf(KoinExtension(testModule))
val tagRepository by inject<ITagRepository>()
val databaseManager by inject<IDatabaseManager<Database, Collection>>()
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....
Hi, I need some help please,
I want to do some tests using Instrumented in Android (I need to get the appContext, to get the directory to create my test db).
But I was having the error:
No instrumentation registered! Must run under a registering instrumentation.
Now, with Kotest, your extension and Roboeletric, I can make Android Studio recognize my class to test as Instrumented test, but now I have the error:
basic:
My code is:
My test class in commonTest:
In my
androidInstrumentedTest
directory, I have:Why I'm getting this error? Why it doesn't recognize my tests?
Thanks in advance!
The text was updated successfully, but these errors were encountered: