Skip to content

Commit

Permalink
WIP Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBg committed Feb 4, 2020
1 parent d159ce5 commit 691ba90
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 33 deletions.
8 changes: 3 additions & 5 deletions Examples/DemoApp/buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object AndroidX {

object Coroutines {

private const val version = "1.3.3"
const val version = "1.3.3"

const val common = "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
Expand Down Expand Up @@ -108,8 +108,6 @@ object Ktor {
object Tests {

const val junit = "junit:junit:4.13"
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Coroutines.version}"
const val mockk = "io.mockk:mockk:1.9.3"
const val androidxTestCore = "androidx.test:core:1.2.0"
const val androidxTestJuint = "androidx.test.ext:junit:1.1.1"
const val robolectric = "org.robolectric:robolectric:4.0"
}
}
11 changes: 3 additions & 8 deletions Examples/DemoApp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,16 @@ kotlin {

getByName("commonTest").dependencies {
implementation(kotlin("test-common", Build.Versions.kotlin))
implementation(kotlin("test-junit", Build.Versions.kotlin))
implementation(kotlin("test-annotations-common", Build.Versions.kotlin))
implementation(Coroutines.common)
implementation(Tests.coroutines)
implementation(Tests.mockk)
}

getByName("androidTest").dependencies {
implementation(kotlin("test", Build.Versions.kotlin))
implementation(kotlin("test-junit", Build.Versions.kotlin))
implementation(kotlin("test-annotations-common", Build.Versions.kotlin))
implementation(Coroutines.android)
implementation(Tests.junit)
implementation(Tests.mockk)
implementation(Tests.androidxTestCore)
implementation(Tests.androidxTestJuint)
implementation(Tests.robolectric)
implementation(Tests.coroutines)
}

getByName("iosTest").dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.jtouzy.demo.common

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher

@ExperimentalCoroutinesApi
internal actual fun <T> runTest(block: suspend () -> T): T {
return runBlocking { block() }
return runBlocking(TestCoroutineDispatcher()) { block() }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import com.jtouzy.demo.common.runTest
import com.jtouzy.demo.network.dto.CharacterDto
import com.jtouzy.demo.ui.Store
import com.jtouzy.demo.ui.model.Character
import io.mockk.coEvery
import io.mockk.coVerifyOrder
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.*
import kotlin.test.Test

open class CharactersPresenterTest {
class CharactersPresenterTest {

private val dtoCharacters = listOf(
CharacterDto("Toto", "url"),
Expand All @@ -33,9 +30,9 @@ open class CharactersPresenterTest {
@Test
fun `should return characters when call is successful`() {
runTest {
presenter.loadCharacters()
presenter.asyncLoadCharacters()

coVerifyOrder {
verifyOrder {
store.viewState = CharactersViewState.Loading
store.viewState = CharactersViewState.Content(characters)
}
Expand Down

This file was deleted.

0 comments on commit 691ba90

Please sign in to comment.