Robolectric tanks on Application objects that load JNI libraries. Can I get a workaround?

后端 未结 3 1110
悲&欢浪女
悲&欢浪女 2021-01-02 06:11

The Application object for my Android app loads a JNI library, and Robolectric doesn\'t seem to like that. When I go to run my tests Robolectric craps out and I

3条回答
  •  执笔经年
    2021-01-02 06:46

    One option for apps with heavyweight Application classes that don't work well with Robolectric is to create an empty Application object and use this for your Robolectric tests:

    Something like this:

    public void EmptyApp extends Application { 
    }
    

    Then your test setup can look like this:

    @RunWith(RobolectricTestRunner.class)
    @Config(application = EmptyApplication.class, manifest = "src/main/AndroidManifest.xml", sdk = 23)   
    

    Since you have referenced the manifest, all of the resources will still be available in Context#getString(int id) and so on.

提交回复
热议问题