Skip to content

Commit

Permalink
Migrate method based test to behavior based test
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Jul 15, 2024
1 parent 9476bc6 commit c20f68f
Showing 1 changed file with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.droidkaigi.confsched.testing.DefaultEventMapServerRobot
import io.github.droidkaigi.confsched.testing.DefaultScreenRobot
import io.github.droidkaigi.confsched.testing.DescribedBehavior
import io.github.droidkaigi.confsched.testing.EventMapServerRobot
import io.github.droidkaigi.confsched.testing.EventMapServerRobot.ServerStatus.Operational
import io.github.droidkaigi.confsched.testing.RobotTestRule
import io.github.droidkaigi.confsched.testing.ScreenRobot
import io.github.droidkaigi.confsched.testing.describeBehaviors
import io.github.droidkaigi.confsched.testing.execute
import io.github.droidkaigi.confsched.testing.runRobot
import io.github.droidkaigi.confsched.testing.todoChecks
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import javax.inject.Inject

@RunWith(AndroidJUnit4::class)
@RunWith(ParameterizedRobolectricTestRunner::class)
@HiltAndroidTest
class EventMapScreenTest {
class EventMapScreenTest(val behavior: DescribedBehavior<EventMapScreenRobot>) {

@get:Rule
@BindValue val robotTestRule: RobotTestRule = RobotTestRule(this)
Expand All @@ -26,26 +31,38 @@ class EventMapScreenTest {
lateinit var eventMapScreenRobot: EventMapScreenRobot

@Test
fun checkScreenContent() {
runRobot(eventMapScreenRobot) {
setupEventMapServer(EventMapServerRobot.ServerStatus.Operational)
setupScreenContent()

captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
}
fun test() = runRobot(eventMapScreenRobot) {
behavior.execute(eventMapScreenRobot)
}

@Test
fun checkErrorScreenContent() {
runRobot(eventMapScreenRobot) {
setupEventMapServer(EventMapServerRobot.ServerStatus.Error)
setupScreenContent()

captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters(name = "{0}")
fun behaviors(): List<DescribedBehavior<EventMapScreenRobot>> {
return describeBehaviors<EventMapScreenRobot>(name = "TimetableScreen") {
describe("when server is operational") {
run {
setupEventMapServer(Operational)
setupScreenContent()
}
itShould("show event map items") {
captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
}
}
describe("when server is error") {
run {
setupEventMapServer(EventMapServerRobot.ServerStatus.Error)
setupScreenContent()
}
itShould("show error message") {
captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
}
}
}
}
}
}
Expand Down

0 comments on commit c20f68f

Please sign in to comment.