Skip to content

Latest commit

 

History

History
77 lines (66 loc) · 2.43 KB

DEPRECATED.md

File metadata and controls

77 lines (66 loc) · 2.43 KB
title
MockK deprecation

Gitter Build Status Relase Version Change log Matrix tests codecov Documentation GitHub stars

It is important to make right decisions about deprecation of some functionality. Otherwise lib code or user code may become a mess. I know it may be inconvenient for end user, but here sooner is better than later.

Scoped mocking

From the beginning syntax of scoped mocking was weird. But not only that. More and more I am finding that people misusing it in code I see through GH, Gitter and Slack. This misuse exposes tests to errors and dependency.

Old syntaxNew syntaxAnnotation
objectMockk(Obj).use {
   // mocking, usage, verification
}
mockkObject(Obj)
// mocking, usage, verification

mockkObject will automatically clear mock before usage. It is safe to use it alone without clearing or unmocking

staticMockk<Cls>().use {
   // mocking, usage, verification
}
mockkStatic(Cls::class)
// mocking, usage, verification

mockkStatic will automatically clear mock before usage. It is safe to use it alone without clearing or unmocking

So basically there is no scopes, mock, unmock or use. There is just one call that creates a mock or clears if it is already created. It should be safe to have only that one declaration in test before using mock.