Hi, I'm trying to use `runBlocking` in a junit4 `@...
# android
f
Hi, I'm trying to use
runBlocking
in a junit4
@Before
block to setup some test fixtures. This works fine in JVM tests, however, Android tests hang forever. Is that to be expected?
r
Hey! 👋 I'd say it's not necessarily surprising. I believe it's generally ill-advised to run a
runBlocking
block in the setup (or teardown) method as it can cause threading issues.
f
hmm but it's not uncommon to setup some fixture in a setup method no?
how else could I achieve this?
r
In case those to set up are suspending functions I'd suggest setting them up in each test case's
runTest
block to avoid threading issues. Maybe extract these setups into a method private in the test class as an extension on the
TestScope
.
f
yeah that's my current workaround, but it defeats the purpose of a fixture 🤔
r
Maybe wait for some ideas from others if any. 😁
f
yeah let's see 🙂 thanks for your help!
👍🏻 1