KoinAppAlreadyStartedException:Koin应用程序已经启动 [英] KoinAppAlreadyStartedException: A Koin Application has already been started
问题描述
使用koin-2.0.1进行Android测试,尽管每个测试分别通过,但无法同时测试所有3个测试.
Using koin-2.0.1 for Android testing and unable to test all 3 test together though each test passes separately.
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)
}
}
正在运行的班级测试结果如下:
running class level testing resulting below:
org.koin.core.error.KoinAppAlreadyStartedException: A Koin Application has already been started
任何输入都会有所帮助,谢谢.
any input would be helpful, thanks.
推荐答案
作为@After
方法的替代方法,您也可以使用AutoCloseKoinTest
.
As an alternative to the @After
approach, you can also use AutoCloseKoinTest
. As described in the docs:
扩展的Koin测试-嵌入自动关闭@after方法以在每次测试后关闭Koin
Extended Koin Test - embed autoclose @after method to close Koin after every test
您可以扩展AutoCloseKoinTest
而不是扩展KoinTest
,它将为您做事后测试.
Instead of extending KoinTest
, you can extend AutoCloseKoinTest
and it will do the after test for you.
这篇关于KoinAppAlreadyStartedException:Koin应用程序已经启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!