Jeff Lockhart
06/29/2022, 10:18 PM@BeforeClass
behavior in Android/iOS common tests? kotlin.test has the annotation for Kotlin/Native, as does Junit for JVM. My naive attempt to typealias the two doesn't work on the JVM side.ephemient
06/29/2022, 10:20 PM@kotlin.test.BeforeClass
. it already has actual typealias
defined in the kotlin-test-junit
and kotlin-test-junit5
artifactsJeff Lockhart
06/29/2022, 10:23 PMephemient
06/29/2022, 10:24 PMkotlin {
sourceSets {
commonTest {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-test")
or something equivalent in your build.gradle
?Big Chungus
06/29/2022, 10:24 PMJeff Lockhart
06/29/2022, 10:29 PMkotlin {
sourceSets {
...
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
...
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
}
}
ephemient
06/29/2022, 10:31 PM@kotlin.test.BeforeAll
or manually importing it as Martynas suggestsJeff Lockhart
06/29/2022, 10:31 PM@kotlin.test.BeforeClass
and I get the error:
Unresolved reference: BeforeClass
ephemient
06/29/2022, 10:32 PMJeff Lockhart
06/29/2022, 10:32 PM@kotlin.test.BeforeAll
Jeff Lockhart
06/29/2022, 10:32 PMephemient
06/29/2022, 10:34 PMkotlin {
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-annotations-common"))
}
}
}
but that's odd, the same setup works in my projects. do you have a public project?Jeff Lockhart
06/29/2022, 10:34 PMephemient
06/29/2022, 10:35 PMJeff Lockhart
06/29/2022, 10:36 PMephemient
06/29/2022, 10:36 PMandroidTest
and androidAndroidTest
right?Jeff Lockhart
06/29/2022, 10:37 PMephemient
06/29/2022, 10:38 PMandroidTest
in a non-multiplatform android project), not just the former (the equivalent of test
in a non-multiplatform android project)Jeff Lockhart
06/29/2022, 10:39 PM@BeforeTest
annotation. You have @BeforeClass
working the same though?Jeff Lockhart
06/29/2022, 10:40 PMJeff Lockhart
06/29/2022, 10:41 PMJeff Lockhart
06/29/2022, 10:42 PMJeff Lockhart
06/30/2022, 1:09 AMkotlin-test
dependency includes kotlin-test-common
and kotlin-test-annotations-common
. annotations-common contains only 4 annotations: Tests
, Ignore
, BeforeTest
, and AfterTest
. Their definitions are pretty close to what I was attempting to typealias `BeforeClass`:
@Target(AnnotationTarget.FUNCTION)
public expect annotation class BeforeTest()
The kotlin-test-junit
dependency defines the jvm actual:
public typealias BeforeTest = org.junit.Before
Again, similar to what I was attempting for BeforeClass
. There must be some reason that this typealias doesn't work for this annotation. Not sure why though.ephemient
06/30/2022, 1:11 AMJeff Lockhart
06/30/2022, 1:15 AMJeff Lockhart
06/30/2022, 1:45 AMExpected annotation class 'BeforeClass' has no actual declaration in module ...androidTest (test) for JVM
Actual typealias 'BeforeClass' has no corresponding expected declaration
The tests still compile and run, but my function annotated @BeforeClass
does not get run at all.Jeff Lockhart
06/30/2022, 1:52 AMBeforeTest
and AfterTest
, with the same typealiasing, I get the same IDE errors. But the tests run and the annotations work as expected. So the IDE errors don't seem to have anything to do with the issue. There just seems to be something specific about the Junit BeforeClass
behavior that doesn't work from common tests.Jeff Lockhart
06/30/2022, 1:57 AM@JvmStatic
annotation! So really, the kotlin team should be able to add these annotations to the common annotations library.ephemient
06/30/2022, 1:58 AMephemient
06/30/2022, 2:00 AMJeff Lockhart
06/30/2022, 2:20 AM