Issue
When using the Mockk for Android Unit tests, there is any difference of using the notation when declaring dependencies?
class Test {
private val x: X = mockk()
private val test = TestClass(x)
...
}
or
class Test {
@MockK
private lateinit var x: X
@InjectMockKs
private lateinit var test: TestClass
@Before
fun setup() {
MockKAnnotations.init(this)
}
...
}
Solution
From MockK project
No there is no difference between the two implementations, they are equivalent.
Generally speaking, you can use mockk() when you need to declare mocks dynamically in your code, or if you need, for instance, just a single mock to have its unit functions relaxed (in which case you would build it with mockk(relaxUnitFun = true).
If your mocks have all the same behavior, you can use the annotations version.
Answered By - Canato
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.