Robolectric and Android SDK 29

前端 未结 4 1855
闹比i
闹比i 2020-12-29 19:51

When will Robolectric be compatible with Android SDK 29? Did I upgraded too early by changing targetSdkVersion and compileSdkVersion to 29?

相关标签:
4条回答
  • 2020-12-29 20:09

    With Robolectric 4.3.1 we can use the following alternatives:

    1. Run our test with Java 9 or newer. (We can edit the JRE in the run test configuration)

    If we like to run our test with Java 8, we can:

    1. Annotated our test class with @Config in order to emulate a lower SDK (as mentioned by @bencri and @julio-mendoza).

    Like this:

    @RunWith(AndroidJUnit4::class)
    @Config(sdk = [Build.VERSION_CODES.P])
    class LoginRobolectricTest {
    //...
    }
    
    1. Or, as mentioned @farmerbb, add the robolectric.properties file inside the app/src/test/resources folder with the SDK we like to run, by example:

    sdk=28

    0 讨论(0)
  • 2020-12-29 20:18

    Latest Robolectric 4.3 already supports Android Q (https://github.com/robolectric/robolectric/releases)

    0 讨论(0)
  • 2020-12-29 20:23

    Create a robolectric.properties file inside the app/src/test/resources directory with the following line:

    sdk=28
    

    This will force Robolectric to use API 28 instead of 29.

    0 讨论(0)
  • 2020-12-29 20:31

    If anyone is wondering, the solution for me was to annotate my test classes with

    @Config(sdk = Build.VERSION_CODES.O_MR1)
    
    0 讨论(0)
提交回复
热议问题