Hi. I’m trying to use Kotest with Robolectric on a...
# kotest
l
Hi. I’m trying to use Kotest with Robolectric on android local test but I’m getting this error as soon as i run my test:
Copy code
java.lang.IllegalArgumentException: failed to configure io.kotest.extensions.robolectric.ContainedRobolectricRunner$PlaceholderTest.testPlaceholder: Package targetSdkVersion=30 > maxSdkVersion=29
	at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:254)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner.access$getChildren(ContainedRobolectricRunner.kt:7)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner$placeHolderMethod$2.invoke(ContainedRobolectricRunner.kt:10)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner$placeHolderMethod$2.invoke(ContainedRobolectricRunner.kt:7)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner.getPlaceHolderMethod(ContainedRobolectricRunner.kt)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner.access$getPlaceHolderMethod$p(ContainedRobolectricRunner.kt:7)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner$sdkEnvironment$2.invoke(ContainedRobolectricRunner.kt:19)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner$sdkEnvironment$2.invoke(ContainedRobolectricRunner.kt:7)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at io.kotest.extensions.robolectric.ContainedRobolectricRunner.getSdkEnvironment(ContainedRobolectricRunner.kt)
	at io.kotest.extensions.robolectric.RobolectricExtension.instantiate(RobolectricExtension.kt:16)
	at io.kotest.engine.InstantiateSpecKt.createAndInitializeSpec(instantiateSpec.kt:21)
	at io.kotest.engine.spec.SpecExecutor.createInstance(SpecExecutor.kt:103)
	at io.kotest.engine.spec.SpecExecutor.execute(SpecExecutor.kt:43)
	at io.kotest.engine.KotestEngine$submitBatch$$inlined$forEach$lambda$1$1.invokeSuspend(KotestEngine.kt:139)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:270)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at io.kotest.engine.KotestEngine$submitBatch$$inlined$forEach$lambda$1.run(KotestEngine.kt:138)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
test code is here:
Copy code
@RobolectricTest
@Config(sdk = [Build.VERSION_CODES.P])
class ExampleUnitTest: FunSpec ({
    test("test") {
        "aa" shouldBe "aa"
    }
})
How can i fix it?
l
Package targetSdkVersion=30 > maxSdkVersion=29
I believe sdk version 30 is not currently supported
It seems robo itself doesn't support anything >29 at the moment
l
So I set sdk to 29 but it doesn’t work.
l
What error do you get then?
l
exactly same error
l
Are you sure you changed your target sdk? Could you provide us with a sample project to tackle this?
l
As I asked, I added @Config(sdk = [Build.VERSION_CODES.P]) to the code. The project is all that test code without any special code.
l
I believe you need to change your app target sdk version, at least on the test build
l
Isn’t “@Config(sdk = [Build.VERSION_CODES.P])” enough?
l
I don't think so. Try changing that on build.gradle
l
Should I create a script that changes targetSdk when running a test..?
I wanted testOptions to have a property called targetSdkVersion, but it’s not.
According to the Robolectric documentation, specifying @Config is sufficient.
103 Views