与 Time 相关的单元测试在 bitrise 上失败

Unit tests related to Time fail on bitrise

提问人:BRDroid 提问时间:8/16/2023 更新时间:8/16/2023 访问量:25

问:

我有一个单元测试,它在机器上本地通过,但在 bitrise 上它失败了。单元测试有时间。

@Test
fun `If time is later than now in hours, then show in hours`() = runTest {
    clock.setInstant(Instant.ofEpochSecond(1686755085)) //Wed 14 Jun 16:05

    val first = chargeTileInteractor12.observe().first()

    assertEquals("in 3 hours", first.nextSessionDateText)
}

在 Bitrise 单元测试中失败并出现错误org.junit.ComparisonFailure: expected:<in [3] hours> but was:<in [4] hours>

它正在调用的函数

    fun getNextSessionDateText(
        clock: Clock,
        targetDaySeconds: Int,
        timeZoneId: ZoneId
    ): String {
        val date = LocalDateTime.now(clock)
        val nowDaySeconds = date.toLocalTime().toSecondOfDay()
        return if (targetDaySeconds >= nowDaySeconds) {
            val newSeconds = targetDaySeconds - nowDaySeconds
            val newMinutes = secondsToMinutes(newSeconds.toLong())
            val newHours = minutesToHoursRounded(newMinutes)
            if (newHours > 0) {
                "in $newHours hours"
            } else if (newMinutes > 0) {
                "in $newMinutes minutes"
            } else {
                "in $newSeconds seconds"
            }
        } else {
            val newPastSeconds = nowToMidnightSeconds(timeZoneId) + targetDaySeconds
            val newPastMinutes = secondsToMinutes(newPastSeconds)
            val newPastHours = minutesToHoursRounded(newPastMinutes)
            if (newPastHours > 0) {
                "in $newPastHours hours"
            } else if (newPastMinutes > 0) {
                "in $newPastMinutes minutes"
            } else {
                "in $newPastSeconds seconds"
            }
        }
    }

关于如何让它工作的任何建议,请

谢谢 R

android kotlin 单元测试 datetime android-unit-testing

评论


答: 暂无答案