splendo / kaluga

Collection of multiplatform kotlin components, mainly using coroutines and flow
Apache License 2.0
275 stars 6 forks source link

Annotations for test utils #746

Open ChristoferAlexander opened 7 months ago

ChristoferAlexander commented 7 months ago

Is your feature request related to a problem? Please describe.

As proposed by @thoutbeckers here we could do with a test-annotations module on kaluga to gather all commonly used testing annotations.

Describe the solution you'd like

Create annotation for ignoring tests on JavaScript @IgnoreJs

/**
 * Ignore a test when running the test on a JavaScript test runtime.
 */
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
expect annotation class JsIgnore()

jsTest

// Map to Kotlin Ignore attribute so that the test is ignored by JavaScript test runtime.
actual typealias JsIgnore = kotlin.test.Ignore

Rest

// Nothing to do. This should only ignore tests on the JavaScript test runtime.
actual annotation class JsIgnore

Create similar annotations for Jvm and iOS.

Create annotation for running common tests as integration tests @IntegrationTest

commonTest

/**
 * An annotation to indicate that the class represents an integration test.
 * The test is ignored if run as a unit test.
 */
expect annotation class IntegrationTest()

androidInstrumentedTest

@Retention
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
actual annotation class IntegrationTest()

androidUnitTest

actual typealias IntegrationTest = org.junit.Ignore

iOSTest

@Retention
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
actual annotation class IntegrationTest()

jsTest

@Retention
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
actual annotation class IntegrationTest()
ChristoferAlexander commented 7 months ago

@Daeda88 do you see any issues with having @IntegrationTest in kaluga? Also what would be the process to have a common test run as an integration test on Android (Create the task and configure gradle)? I know iOS has no issues running integration tests as it anyway runs all tests on a sim.

Daeda88 commented 7 months ago

Problem is that when you write a library, you can only export the main libraries. That's a problem for Android where you don't have an instrumentationMain or anything. So it's difficult to make this work

thoutbeckers commented 7 months ago

That's a good point we didn't consider @Daeda88.

I suspect it can be done with the correct gradle module metadata but indeed a bit non-trivial to sort out.

The "easy" way is probably to manually specify dependencies for each sourceset, but then you might as well copy/paste the annotations to each sourceset.