Hello! Experienced some unexpected/weird behaviour...
# konsist
d
Hello! Experienced some unexpected/weird behaviour and was thinking of getting some help here. My use case is the following. I want to: Grab all my tests functions, excludes the ones that are android tests kotlin test convention for naming and then assert that they follow our naming scheme (In our case we write them with backticks and thus they should include spaces and also have a "should" or "ensure" keyword) When trying to filter out the tests I do the following:
Copy code
Konsist.scopeFromTest()
    .functions()
    .withAnnotationOf(Test::class)
however this seems to filter out my tests. I then did some debugging and inspected one of my test functions and I see the following: The test has only one annotation, and the
name
is "Test" which is what I would expect (test are annotated with
@Test
from junit5, but when looking at the
fullyQualifiedName
it is
kotlinx.coroutines.test.UnconfinedTestDispatcher
which the Test class was extended with from a
TestCoroutineRule
not the
org.junit.jupiter.api.Test
as I would expect. All other properties e.g
text
,
location
points towards the actual annotation. Any ideas how I get the "real" annotation or why I'm getting the wrong
fullyQualifiedName
?
kotlinx.coroutines.test.UnconfinedTestDispatcher
seems to come from an annotation on the class
ExtendWith
@igor.wojda I believe this might be a bug in Konsist I was looking deeper into this today, the following line find the fullyQualifiedName using firstOrNull: https://github.com/LemonAppDev/konsist/blob/12eb98c15a41be02b100e02e4c3cc74db213f3[…]ppdev/konsist/core/provider/KoFullyQualifiedNameProviderCore.kt
If there are multiple imports in the file having the same keyword as the name for the annotation we might return the wrong fullyQualifiedName
There should probably be a check at at last word in an import to have an exact match on the annotation?
Also not sure how it would handle a wildcard import
I made another test, I moved the import to the top of the list of imports and immediately found the right import
org.junit.jupiter.api.Test
Found out that this was a known issue: https://github.com/LemonAppDev/konsist/discussions/738 I've closed the ticket 🙂
👍 1