android - 单元测试和 joda-time-android

标签 android jodatime mosby

我在 Presenter 中使用了 joda-time-android 库的类类,并且它不能有任何 Android 依赖项。所以我无法正确测试它。我知道我可以为此使用 Robolectric,但我想远离这个工具和我的 Presenter 干净。我应该放弃 JodaTime 吗?还有其他解决方案吗?

最佳答案

对于单元测试,我们可以使用JodaTime 库的默认java 实现,因为它具有与joda-time-android 相同的包和类>.

// for android
compile 'net.danlew:android.joda:2.9.3'

// joda-time for tests
testCompile 'joda-time:joda-time:2.9.3'

像魅力一样工作。

对于其他库的其他情况,请参阅 @npace的答案。

关于android - 单元测试和 joda-time-android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37191083/

相关文章:

android - 如何在屏幕旋转时保持 Presenter 的嵌套 Fragment 实例

android - AsyncTask 和 setContentView

java - 为什么我的 DateTime 反序列化会截断 DateTime 分钟/秒/毫秒?

java - 邻区信息不准确

android - Android : The datetime zone id 'America/New_York' is not recognised 中的 Joda-Time 错误

java - 将字符串转换为 joda 日期时间卡住

android - 如何测试使用 Retrofit 和 Dagger2 的 REST API

android - 什么是 "SQLiteDatabase created and never closed"错误?

android - Android Lollipop 中的共享元素转换故障