Cra*_*1hd 3 testing android unit-testing robolectric kotlin
我在不需要robolectric的情况下无法创建单元测试。我在代码中使用AndroidThreeTen.init(this),如果我禁用了robolectric,则在运行测试时出现错误:
org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered
如果我将其保持启用状态,则会得到以下信息:
[Robolectric] com.mycomp.,yapp.utilities.log.LogTest.on Calling function w it returns an Int: sdk=28; resources=BINARY
我试过使用testImplementation'com.jakewharton.threetenabp:threetenabp:1.1.0'没什么区别。我在应用程序和testApplication中调用了AndroidThreeTen.init(this)。有任何想法吗?这是我的考验
@Test
fun `on Calling function i it returns an Int`() {
assertThat("Returned class is not an Int", Log.i("Test", "Test"), isA(Int::class.java))
assertThat("Returned Int is not 0", Log.i("Test", "Test"), `is`(0))
}
Run Code Online (Sandbox Code Playgroud)
还是因为这个原因我必须使用robolectric吗?(附带说明:日志不是来自android的util.log,而是我自己的类)(已编辑)
JVM单元测试不在Android运行时上运行。代替ThreeTenABP,您可以直接使用ThreeTenBP来为常规JVM初始化相同的API。
在我的项目build.gradle中,我使用类似以下的设置:
implementation "com.jakewharton.threetenabp:threetenabp:${threetenabpVersion}"
testImplementation("org.threeten:threetenbp:${threetenbpVersion}") {
exclude module: "com.jakewharton.threetenabp:threetenabp:${threetenabpVersion}"
}
Run Code Online (Sandbox Code Playgroud)
哪里
threetenabpVersion = '1.2.0'
threetenbpVersion = '1.3.8'
Run Code Online (Sandbox Code Playgroud)
这通常通过ThreeTenABP使用ThreeTenBP,但在单元测试配置中,它直接将TreeTenBP作为依赖项及其初始化代码添加。我不记得我为什么要exclude遵守规则了;已经有好几年了。
| 归档时间: |
|
| 查看次数: |
424 次 |
| 最近记录: |