Just moving from Java to Kotlin. There was a question, the answer to which, unfortunately, I could not find. There is a certain abstract class with several abstract variables, on which dozens of tests will go on. I'm testing with JUnit. The annotated methods @BeforeClass
and @AfterClass
are required to be static, and I see only one way to resolve the gap: push methods inside the companion object
, where you can use @JvmStatic
, but at the same time, an abstract variable is called in the @BeforeClass
method @BeforeClass
is defined by each implementation separately. Correspondingly, how can I access a variable from an external class? Or maybe there is another way to solve this problem? Code:
abstract class TemplateConfig { abstract val template : String? companion object { lateinit var h: Handle @BeforeClass @JvmStatic fun setUp() { h = dbi.value.open() //Здесь используется абстрактная переменная // //if (template != null) { // h.createStatement(template).execute() //} } @AfterClass @JvmStatic fun tearDown() { h.close() } //{...Объявление и инициализация других переменных...} } }