Is there any way to define `@BeforeClass` / `@Afte...
# multiplatform
j
Is there any way to define
@BeforeClass
/
@AfterClass
in multiplatform common tests? AFAICT these annotations are JVM-only at the moment šŸ˜ž I could add cleanup after each test, but that's a bit overkill, and may not work for every use case.
e
there's kotlin.test.BeforeClass/kotlin.test.AfterClass on native, but right, nothing for JS/common
j
@ephemient Ok, thanks, that's what I feared... šŸ˜­
@Big Chungus this is
@Before
/`@After` behaviour, where setup/cleanup is executed for each test. I'm looking for a single setup/cleanup for all tests.
b
@Before Old can easily be added to that class. @After might be more tricky
Oops, accidentally tagged someone
But in most cases beforeEach and afterEach are good alternatives to before and after if you don't mind losing a bit of performance
j
@BeforeTest
and
@AfterTest
are already supported out of the box on all platforms, though: https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/-before-test/ https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/-after-test/ So I already have this option without extra hack (which is what I'm doing now), but I wanted to have class-level hooks to avoid unnecessary work (I use these hooks to generate reports).
b
Hmm, can't recall why I've made my own. But I was aware of those already.
e
it looks like QUnit, Jasmine, Mocha, Jest, and Karma all support some form of beforeAll()/afterAll() (called before()/after() in some), so I feel like Kotlin's test adapter should be able to translate somehowā€¦ I don't know how to make that happen, though.
j
Yeah I have the same feeling. Since it's explicitly stated in the
BeforeClass
docs that it's not supported in common code, I don't think the Kotlin team just "forgot". There is likely some blocker they must have faced but I'd be interested in knowing what exactly.
I haven't found any open issue in YouTrack regarding this, btw. Will probably open one for tracking