Tests can run on prior versions as a temporary workaround
You will not be able to run Robolectric against SDK 29 for now (27 April 2020), but this will likely be updated in the future. Currently, as all of the answers before me pointed out, there is no support of Java 9 or later in Android Studio.
But if you are here to make your Robolectic tests run you could simply avoid SDK 29 by setting the Robolectric @Config
annotation for your class. Robolectric will simply run your tests against all of the supported SDK versions of your app except 29.
Implement
Set the maxSdk
and minSdk
versions to run on. This can be based on the app's min and max SDK versions, or set to one version like below in order to make tests faster.
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.robolectric.annotation.Config
import org.junit.runner.RunWith
import android.os.Build
@RunWith(AndroidJUnit4::class)
@Config(maxSdk = Build.VERSION_CODES.P, minSdk = Build.VERSION_CODES.P) // Value of Build.VERSION_CODES.P is 28
class TestClass {
...
}
Of course it is just another "ugly" patch, but it will get you going until you'll be able to run tests against all of the desired SDKs, or at least SDK 29 and all below.