https://kotlinlang.org logo
Title
a

Ahmed Mourad

10/04/2020, 7:42 PM
How do I configure Robolectric tests? Doing this doesn't seem to work:
@Config(sdk = [Build.VERSION_CODES.O_MR1])
@RobolectricTest
class SomeTest : DescribeSpec({ ... })
w

wasyl

10/04/2020, 7:57 PM
Sadly if I understand correctly there’s no way to provide configuration when running Robolectric tests in Kotest
At least that was my conclusion from the last time I tried to do that
a

Ahmed Mourad

10/04/2020, 10:00 PM
That's unfortunate! I managed to replace that by adding a
robolectric.properties
file, but now I'm getting this error:
java.lang.IllegalStateException: this method should only be called by Robolectric
Which is also reported here: https://github.com/kotest/kotest/issues/1620 Did you manage to get Robolectric to work here? Is there a way around this?
w

wasyl

10/05/2020, 7:18 AM
We tried to build our own Robolectric extension (planning to contribute it back to Kotest repo) but it proved to be quite difficult to support configuration as well as Kotest features (for example isolation mode). Ultimately the issue is with JUnit5 not supporting per-test classloader (https://github.com/junit-team/junit5/issues/201) as well as with Robolectric not supporting JUnit5 (https://github.com/robolectric/robolectric/issues/3397). We decided to not write our Robolectric tests in Kotest until these two are fixed and proper, non-hacky support can be added
s

sam

10/05/2020, 10:03 AM
A four year old ticket wow
I looked at this once. The junit listener they use would need to be written again from scratch in kotlin
w

wasyl

10/05/2020, 10:08 AM
JUnit5 issue is in 5.8 milestone, which is the next bigger release. Hopefully they’ll be able to implement it, and Robolectric will follow
s

sam

10/05/2020, 10:13 AM
Ok junit5 will be good