Recall & Review
beginner
What is MockK in Android Kotlin testing?
MockK is a Kotlin library used to create mock objects for unit testing. It helps simulate behavior of real objects to test code in isolation.
Click to reveal answer
beginner
How do you create a mock object with MockK?
Use the function
mockk<ClassName>() to create a mock instance of a class.Click to reveal answer
intermediate
What does the
every { ... } returns ... syntax do in MockK?It defines the behavior of a mocked function call. When the function inside
every { } is called, it returns the specified value.Click to reveal answer
intermediate
How do you verify that a mocked function was called in MockK?
Use the
verify { mock.functionName() } block to check if the function was called during the test.Click to reveal answer
advanced
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 can call real methods unless mocked.Click to reveal answer
Which function creates a mock object in MockK?
✗ Incorrect
The
mockk() function creates a mock object in MockK.How do you specify the return value of a mocked function in MockK?
✗ Incorrect
In MockK, use
every { function() } returns value to specify return values.What does the
verify { ... } block do in MockK?✗ Incorrect
The
verify { ... } block checks if a mocked function was called during the test.Which MockK function creates a spy that calls real methods unless mocked?
✗ Incorrect
spyk() creates a spy that wraps a real object and calls real methods unless mocked.What is the main purpose of using MockK in Android testing?
✗ Incorrect
MockK is used to simulate object behavior to isolate and test code in unit tests.
Explain how to create and use a mock object with MockK in a Kotlin unit test.
Think about how you tell the mock what to do and how to check it was used.
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 fake everything or keep some real behavior.
You got /4 concepts.