Suppressing warnings about an unused Kotlin property in IDEA

1k Views Asked by At

Consider I have a parameterized TestNG test:

val parameters: Array<Array<Any>>
    @DataProvider
    get() {
        val parameters = arrayListOf<Array<Any>>()
        // ...
        return parameters.toTypedArray()
    }

@Test(dataProvider = "getParameters")
fun test(p1: Any, pN: Any) {
    // ...
}

How do I stop IDEA from complaining that the data provider property (parameters in our case) is unused? Annotating the property with @get:SuppressWarnings("unused") is not helpful.

2

There are 2 best solutions below

0
On BEST ANSWER

There turned out to be a workaround. Rewriting the annotation like this:

@get:DataProvider
val parameters: Array<Array<Any>>

makes IDEA treat the property as an entry point.

The corresponding ticket is KT-28031.

1
On

Add this on top of the declaration of the parameters property: @Suppress("unused")

You might need to re-compile the project to get IntelliJ to stop highlighting it as an unused property.