使用 koin-2.0.1 进行 Android 测试,尽管每个测试都单独通过,但无法同时测试所有 3 个测试。
class NumberFormatterUtilImplTest : KoinTest {
private val numberFormatterUtil: NumberFormatterUtilImpl by inject()
@Before
fun setUp() {
startKoin { modules(utilsModule) }
}
@Test
fun `does formatter returns two digit faction if supplied one digit value`() {
val result = numberFormatterUtil.getAdjustedCurrencyRate(18.0)
Assert.assertEquals(result, 18.00, 1.0)
}
@Test
fun `does formatter returns two digit faction if supplied multiple digits value`() {
val result = numberFormatterUtil.getAdjustedCurrencyRate(18.12343)
Assert.assertEquals(result, 18.12, 1.0)
}
@Test
fun `does formatter returns rounded two digit faction if supplied multiple digits value`() {
val result = numberFormatterUtil.getAdjustedCurrencyRate(18.12876)
Assert.assertEquals(result, 18.13, 1.0)
}
}
运行类级别测试结果如下:
org.koin.core.error.KoinAppAlreadyStartedException: A Koin Application has already been started
任何输入都会有所帮助,谢谢。