test updates

This commit is contained in:
John O'Reilly 2022-01-01 10:31:43 +00:00
parent a1afb99d80
commit 7924d4ea98
7 changed files with 51 additions and 42 deletions

View file

@ -59,4 +59,4 @@ jobs:
with:
api-level: 29
target: google_apis
script: ./gradlew app:connectedAndroidTest common:connectedAndroidTest
script: ./gradlew app:connectedAndroidTest

View file

@ -59,6 +59,7 @@ object Deps {
object Kotlinx {
const val serializationCore = "org.jetbrains.kotlinx:kotlinx-serialization-core:${Versions.kotlinxSerialization}"
const val coroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
const val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutines}"
const val htmlJs = "org.jetbrains.kotlinx:kotlinx-html-js:${Versions.kotlinxHtmlJs}"
}

View file

@ -71,7 +71,7 @@ kotlin {
}
with(Deps.Kotlinx) {
implementation(Deps.Kotlinx.coroutinesCore)
implementation(coroutinesCore)
implementation(serializationCore)
}
@ -90,6 +90,10 @@ kotlin {
}
}
sourceSets["commonTest"].dependencies {
implementation(Deps.Koin.test)
implementation(Deps.Kotlinx.coroutinesTest)
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
sourceSets["androidMain"].dependencies {

View file

@ -1,18 +0,0 @@
package com.surrus.peopleinspace
import com.surrus.common.di.initKoin
import com.surrus.common.remote.PeopleInSpaceApi
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertTrue
import org.junit.Test
class PeopleInSpaceTest {
@Test
fun testGetPeople() = runBlocking {
val koin = initKoin(enableNetworkLogs = true).koin
val peopleInSpaceApi = koin.get<PeopleInSpaceApi>()
val result = peopleInSpaceApi.fetchPeople()
println(result)
assertTrue(result.people.isNotEmpty())
}
}

View file

@ -75,12 +75,9 @@ class PeopleInSpaceRepository : KoinComponent, PeopleInSpaceRepositoryInterface
override suspend fun fetchPeople(): List<Assignment> = peopleInSpaceApi.fetchPeople().people
override fun pollISSPosition(): Flow<IssPosition> {
// The returned will be frozen in Kotlin Native. We can't freeze the Koin internals
// so we'll use local variables to prevent the Koin internals from freezing.
val api = peopleInSpaceApi
return flow {
while (true) {
val position = api.fetchISSPosition().iss_position
val position = peopleInSpaceApi.fetchISSPosition().iss_position
emit(position)
logger.d { position.toString() }
delay(POLL_INTERVAL)

View file

@ -0,0 +1,43 @@
package com.surrus.peopleinspace
import com.surrus.common.di.PeopleInSpaceDatabaseWrapper
import com.surrus.common.di.commonModule
import com.surrus.common.repository.PeopleInSpaceRepositoryInterface
import com.surrus.common.repository.platformModule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.koin.core.context.startKoin
import org.koin.dsl.module
import org.koin.test.KoinTest
import org.koin.test.inject
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertTrue
class PeopleInSpaceTest: KoinTest {
private val repo : PeopleInSpaceRepositoryInterface by inject()
@BeforeTest
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher())
startKoin{
modules(
commonModule(true),
platformModule(),
module {
single { PeopleInSpaceDatabaseWrapper(null) }
}
)
}
}
@Test
fun testGetPeople() = runTest {
val result = repo.fetchPeople()
println(result)
assertTrue(result.isNotEmpty())
}
}

View file

@ -1,18 +0,0 @@
package com.surrus.peopleinspace
import com.surrus.common.di.initKoin
import com.surrus.common.repository.PeopleInSpaceRepositoryInterface
import kotlinx.coroutines.runBlocking
import kotlin.test.Test
import kotlin.test.assertTrue
class PeopleInSpaceTest {
@Test
fun testGetPeople() = runBlocking {
val koin = initKoin(enableNetworkLogs = true).koin
val repo = koin.get<PeopleInSpaceRepositoryInterface>()
val result = repo.fetchPeople()
println(result)
assertTrue(result.isNotEmpty())
}
}