Skip to content

lateinit property has not been initialized #47

@alexxxdev

Description

@alexxxdev

I have this code:

interface IFoo

class Foo:IFoo {
	fun method(){
		// ...
	}
}

abstract class AbstractBar<T:IFoo>{
    @Inject
    lateinit var foo: T
}



class Bar: AbstractBar<Foo>() {
    fun call(){
        foo.method()
    }
}

class Test {
    @MockK
    lateinit var foo: Foo

    @InjectMockKs lateinit var bar: Bar

    @Before
    fun setUp() = MockKAnnotations.init(this)


    @Test
    fun test() {
        every { foo.method() } answers { nothing }
        bar.call()
        verify { foo.method() }
    }
}

and it produces an error:
kotlin.UninitializedPropertyAccessException: lateinit property foo has not been initialized

mockk version: 1.7.12

What do I need to do to get it right? or is it a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions