-
Notifications
You must be signed in to change notification settings - Fork 0
What is MockK
Devrath edited this page Mar 2, 2024
·
4 revisions
- When we are testing a class, There are dependencies present that are needed for the functioning of the class.
- So when we are testing that class, we can make it such that the dependencies return a stubbed result as we expect for that test case.
- So when we are writing the test case, actually we will be testing the SUT(system under test) rather than the dependencies itself.
- MockK is a mocking framework used in kotlin for writing unit tests.
- It is used for creating mock objects of real objects.
- We can mock the objects and modify the properties.
- In the mock object, We can Stub the methods and verify the interactions.
- It supports all the features of kotlin.
- Mockito cannot
mock
orspy
final classes-
Possible Solution:
- We could make the class open or use interfaces but it requires modifying the code.
- We could use
mockito-kotlin
wrapper but it requires additional boilerplate code. - Mockito doesn't support
private
static
functions instead we might need to usepower-mock
for this.
-
Alternative:
mockK
is a better option for Mockito.
-
Possible Solution:
- MockK is built for kotlin.