Recall & Review
beginner
What is MockK used for in Kotlin testing?
MockK is a library used to create mock objects in Kotlin tests. It helps simulate and control the behavior of dependencies to test code in isolation.
Click to reveal answer
beginner
How do you create a simple mock object with MockK?
Use the function
mockk<ClassName>() to create a mock instance of a class. For example, val mock = mockk<MyClass>().Click to reveal answer
beginner
What does the
every { ... } returns ... syntax do in MockK?It defines the behavior of a mocked function. Inside
every { ... } you specify the function call, and returns sets what value it should return when called.Click to reveal answer
intermediate
How do you verify that a mocked function was called in MockK?
Use the
verify { ... } block with the function call inside. This checks if the function was called during the test.Click to reveal answer
intermediate
What is the difference between
mockk() and spyk() in MockK?mockk() creates a pure mock with no real behavior, while spyk() creates a spy that wraps a real object and allows you to mock or verify some behavior while keeping the original behavior for others.Click to reveal answer
Which MockK function creates a mock object?
✗ Incorrect
mockk() creates a mock object. spyk() creates a spy, every() sets behavior, and verify() checks calls.
How do you specify what a mocked function should return?
✗ Incorrect
You use every { functionCall } returns value to define return values for mocked functions.
What does
verify { mock.someFunction() } check?✗ Incorrect
verify { ... } checks if the specified function was called on the mock.
Which MockK function lets you keep original behavior but mock some parts?
✗ Incorrect
spyk() creates a spy that wraps a real object, allowing partial mocking.
What is the main purpose of mocking in tests?
✗ Incorrect
Mocking helps isolate the code under test by simulating dependencies, so tests focus on the code itself.
Explain how to create a mock and define its behavior using MockK.
Think about how you tell a mock what to do when a function is called.
You got /3 concepts.
Describe the difference between a mock and a spy in MockK and when you might use each.
Consider if you want to keep original behavior or replace it completely.
You got /3 concepts.