Skip to content

Commit

Permalink
Merge pull request #120 from kitakkun/feature/fix_android_test_fails
Browse files Browse the repository at this point in the history
Fix Android Tests
  • Loading branch information
kitakkun authored Jul 16, 2024
2 parents 4d489e5 + fd72ea4 commit 895cbd3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 49 deletions.
5 changes: 5 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ kotlin {
implementation(libs.androidx.compose.runtime)
}
}
val androidUnitTest by getting {
dependencies {
implementation(libs.robolectric)
}
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.kitakkun.backintime.test

import io.github.kitakkun.backintime.runtime.BackInTimeDebugService
import io.github.kitakkun.backintime.runtime.getBackInTimeDebugService
import io.github.kitakkun.backintime.runtime.internal.BackInTimeCompilerInternalApi
import io.github.kitakkun.backintime.test.base.MockConnector
import io.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import kotlin.test.AfterTest
import kotlin.test.BeforeTest

/**
* copy of BackInTimeDebugServiceTest.kt in jvmTest
*/
@RunWith(RobolectricTestRunner::class)
abstract class BackInTimeDebugServiceTest {
@OptIn(BackInTimeCompilerInternalApi::class)
private val service: BackInTimeDebugService = getBackInTimeDebugService(useInUnitTest = true)
private val mockConnector = MockConnector()
private val events: List<BackInTimeDebugServiceEvent> get() = mockConnector.eventsFromService

val registerInstanceEvents get() = events.filterIsInstance<BackInTimeDebugServiceEvent.RegisterInstance>()
val propertyValueChangeEvents get() = events.filterIsInstance<BackInTimeDebugServiceEvent.NotifyValueChange>()
val methodCallEvents get() = events.filterIsInstance<BackInTimeDebugServiceEvent.NotifyMethodCall>()
val registerRelationShipEvents get() = events.filterIsInstance<BackInTimeDebugServiceEvent.RegisterRelationship>()

@BeforeTest
fun setup() {
service.setConnector(mockConnector)
service.startService()
}

@AfterTest
fun teardown() {
service.stopService()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ class StateFlowCaptureTest : BackInTimeDebugServiceTest() {

viewModel.updateValues()

val values = propertyValueChangeEvents.map { it.propertyValue }
val expectedValues = listOf("Hoge", "Fuga", "Piyo", "Foo", "Bar", "Baz")
val values = propertyValueChangeEvents.map { it.value }
val expectedValues = listOf(
"\"Hoge\"",
"\"Fuga\"",
"\"Piyo\"",
"\"Foo\"",
"\"Bar\"",
"\"Baz\""
)
assertEquals(expectedValues, values)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.kitakkun.backintime.test.base
import io.github.kitakkun.backintime.runtime.connector.BackInTimeWebSocketConnector
import io.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent
import io.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow

Expand All @@ -19,7 +20,7 @@ class MockConnector : BackInTimeWebSocketConnector {
}

override suspend fun awaitCloseSession() {
// no-op
awaitCancellation()
}

override suspend fun sendEventToDebugger(event: BackInTimeDebugServiceEvent) {
Expand Down

0 comments on commit 895cbd3

Please sign in to comment.