Kotlintest interceptor and lateinit vars

Answer #1 100 %

????? ?????'s answer is incorrect. This is not how kotlintest works - in init lambdas are only created, not run. So you are not accessing your lateinit vars in init block. They just never have any value assigned.

This doesn't work because of bug in kotlintest, described (and actually almost resolved) here: https://github.com/kotlintest/kotlintest/issues/174

In short - interceptTestCase is called on different instance of class than real tests. So it has no influence on your tests at all.

Workaround is to override property: override val oneInstancePerTest = false

Then there is only one instance and interceptTestCase works correctly, but you have to remember - there is only one instance for all tests.

Kotlintest 3.0 will be free of this bug. (But possibly might have one instance for all tests by default.)

You’ll also like:

© 2023 CodeForDev.com -