I want to test class B:
class B : A {
override fun init() {
// do work here
}
}
class A {
protected fun init() { } // will be called by internal logic
}
and in Java there is no problem to call: b.init()
within test method (test class is in the same package as test subject), but in Kotlin compiler complains:
Cannot access 'init': it is protected in 'B'
@Test
fun `checks init`() {
val b = B()
b.init()
// assert work done
}
Why isn't it working? How can this be workaround (I want to avoid making method public)?
internal
not possible and withpublic
not really acceptable - especially since I can do it in Java – Conservancy