1

I'm trying to migrate test framework from JUnit 5 to kotest.

I selected Annotation Spec at first (to check compatibility), but Nested Annotation doesn't work as expected

Sample code is below

class Outside : AnnotationSpec() {

    @Test
    fun runOutside() { }

    @Nested
    inner class Inside() {
        @Test
        fun runInside() { }
    }
}

runOutside runs well, but runInside doesn't. The error message is java.lang.IllegalArgumentException: object is not an instance of declaring class

What's wrong ? is this a bug ?

cjlee
  • 378
  • 3
  • 10
  • Kotest and JUnit both provide `@Test` and `@Nested` annotations - which ones are you using? Can you include the imports in your sample code? What version of Kotest and Kotlin are you using? How are you running the tests - Maven, Gradle, IntelliJ? – aSemy Jul 09 '22 at 12:46
  • I imported them from kotest(Actually, there are no `import` codes because those annotations are inside in `AnnotationSpec` class). Kotlin version is 1.6.10 and kotest is 5.3.2, and I tried to run tests with both of gradle and intellij – cjlee Jul 10 '22 at 05:32
  • I assume that this is because `Inside` class is `inner class` instead of nested class. I took a look test code in kotest source code, but couldn't find the case of '`inner` class. – cjlee Jul 10 '22 at 05:34
  • Yes this looks like a bug, thanks for making [an issue](https://github.com/kotest/kotest/issues/3103). I see in the source code for Kotest there aren't any tests for `@Nested`... but there's [one commented-out example](https://github.com/kotest/kotest/blob/4af10c624be33d39b88d7241765fdffb08758999/kotest-framework/kotest-framework-engine/src/jvmTest/kotlin/com/sksamuel/kotest/engine/spec/annotation/AnnotationSpecTest.kt#L83-L95) that indicates the nested class is supposed to also be a subclass of `AnnotationSpec` - although I've tried this and it doesn't work! – aSemy Jul 10 '22 at 07:04
  • At this point I'd migrate to one of the other specs – LeoColman Jul 11 '22 at 22:13

0 Answers0