-
Notifications
You must be signed in to change notification settings - Fork 0
Testing library β mockk
Devrath edited this page Oct 24, 2023
·
14 revisions
Contents |
---|
Projects official Github |
How it is useful |
When we use relaxed param in mockk |
When to use every{ ... } and when to use coEvery{ ... } |
- So we know when we have a class used in another class, We can make a
fake
version of that class and pass the fake implementation where it is being used to avoid errors in the actual implementation. - There is another way where we can mock it.
- Basically mocking involves using a
mirror version
of theactual class implementation
and once it is mirrored we can make the methods of that particular class behave as we want so that when theimplementation
of the class is used in another class they return or respond in a particular way.
- Consider the code
mockk()
and compared to anothermockk(relaxed = true)
- When
relaxed=true
is used the framework will give random values likeempty
,false
, etc .. for the functions that contain return types otherwise the return types are not provided, and the mocked instance bay gives an error while running the test. - Also we use this when we need the instance and do not bother with specific return types so random return types are fine.
- When normal functions are to be invoked we used
every { ... }
- When sus[end functions are involved , We use
coEvery{ ... }