https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

Distractic

11/02/2023, 6:38 PM
Hello I want to create a multiplatform library but I have an issue with tests. I would like perform suspend action in the
@BeforeTest
(there is no
@BeforeAll
) but this function cannot be suspend and
runBlocking
doesn't exists in module
commonTest
. I tried to use
runTest
with
@BeforeTest
, but that doesn't work in JS, the test is executed before the end of the Before So, do you advise me to create my tests only in JVM or have you a solution to resolve that ?
1
m

mkrussel

11/02/2023, 6:42 PM
I would probably create a private suspend function that each test calls instead of using
BeforeTest
. You could also create a private
runTest
function that calls the normal runTest function and then calls your setup code and finally runs the test block.
d

Distractic

11/02/2023, 6:46 PM
I tried to call the BeforeEach in each test and effectively, that works, but that's sad if I need to do that everywhere 😣
m

mkrussel

11/02/2023, 6:48 PM
If you weren't support JS you could do the runBlocking. But that is why I recommended you replace the
runTest
with one that calls it, so that the tests don't look different than normal.
c

Casey Brooks

11/02/2023, 6:48 PM
You might take a look at #kotest instead of using the standard Kotlin test framework
d

Distractic

11/02/2023, 6:49 PM
I tried too .. but I can't launch with JS or native directly on the IDE and the plugin doesn't detect the JDK
So, have a custom runTest is acceptable, that allows me to define beforeeach and aftereach However, have you a solution for BeforeAll and AfterAll ? 🤔
Finally, I resolve my bug with Kotest and go on it
2 Views