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

后端 未结 3 1121
悲&欢浪女
悲&欢浪女 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:43

    As @Jared pointed out, the solution @Christopher gave doesn't work for Robolectric 2 or 3.

    The solution I ended up using was to add the environmental variable:

    ROBOLECTRIC=TRUE
    

    to the build configuration for my tests. (Run -> Edit Configurations, Environmental Variables).

    Then you check for that environmental variable before loading problematic libraries. For example:

    class MyClass {
        if(System.getenv("ROBOLECTRIC") == null) {
            System.loadLibrary("libname");
        }
    }
    

    Obviously you won't be able to test any code that relies on that library, but at least some testing will be possibel!

提交回复
热议问题