Skip to content

Commit

Permalink
Make tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBg committed Feb 4, 2020
1 parent d159ce5 commit ed58b6a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
10 changes: 4 additions & 6 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 @@ -107,9 +107,7 @@ object Ktor {

object Tests {

const val junit = "junit:junit:4.13"
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Coroutines.version}"
const val androidxTestJunit = "androidx.test.ext:junit:1.1.1"
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"
}
}
8 changes: 2 additions & 6 deletions Examples/DemoApp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,9 @@ kotlin {
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)
implementation(Tests.androidxTestJunit)
}

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() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jtouzy.demo.ui.characters

import org.junit.Test

class CharactersPresenterTestJvm : CharactersPresenterTest() {

@Test
fun performTests() {
`should return characters when call is successful`()
`should return an error when call is unsuccessful`()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ 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 {
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 All @@ -46,7 +43,7 @@ open class CharactersPresenterTest {
fun `should return an error when call is unsuccessful`() {
runTest {
coEvery { dataStore.getCharacters() } throws IllegalStateException("error")
presenter.loadCharacters()
presenter.asyncLoadCharacters()

coVerifyOrder {
store.viewState = CharactersViewState.Loading
Expand Down

This file was deleted.

0 comments on commit ed58b6a

Please sign in to comment.