Search code examples
androidjodatimemosby

Unit-tests and joda-time-android


I used joda-time-android library's classes in my Presenter class and it must not have any Android dependencies. So I can't test it properly. I know that I can use Robolectric for this, but I want to keep out of this tool and my Presenter clean. Should I abandon JodaTime? Any other solution?


Solution

  • For Unit-tests we can use default java implementation of JodaTime library because it has the same package and classes as 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'
    

    Works like a charm.

    For other cases with other libraries see @npace's answer.