Ausführen eines instrumentierten und im KMP -Projekts ausführenAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Ausführen eines instrumentierten und im KMP -Projekts ausführen

Post by Anonymous »

Ich brauche Hilfe bitte, < /p>
Ich möchte einige Tests mit instrumentiertem Android durchführen (ich muss den AppContext erhalten, um das Verzeichnis zum Erstellen meines Test -DB zu erhalten). Muss unter einer Registrierungsinstrumentierung ausgeführt werden. 'com.diegogaona.cocktailhype.data.repository.tagaRepositoryDBTEST': < /p>

Code: Select all

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>
Mein Code ist:
Meine Testklasse im Commonest: < /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>
In meinem AndroidinStrumentedTest-Verzeichnis habe ich: < /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>
Warum bekomme ich diesen Fehler? Warum erkennt es meine Tests nicht? < /P>
Vielen Dank im Voraus! Muss unter einer Registrierungsinstrumentierung ausgeführt werden. 
.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post