lundi 2 novembre 2020

Junit 4 test inner class in kotlin

I use Junit4 and kotlin.

I use the Enclosed for the inner class test.

import org.junit.Test
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith

@RunWith(Enclosed::class)
class SampleTest {

    var text = "parent class"

    class Class1 {
        @Test
        fun `print the text`() {
            println(text)
        }
    }

    inner class Class2 {
        @Test
        fun `print the text`() {
            println(text)
        }
    }

}

in Class1 and Class2, need the text variable.

I use the inner for an access child class to parent class.

but I have a problem, the test function is removed and I can't test that. see the photo.

enter image description here

can I test the inner class in kaolin with Junit4?

Aucun commentaire:

Enregistrer un commentaire