0
0
Android Kotlinmobile~5 mins

MockK for mocking in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Amockk()
Bspy()
Cstub()
Dfake()
How do you specify the return value of a mocked function in MockK?
Awhen(function()).thenReturn(value)
Bmock(function()).returns(value)
Cgiven(function()).willReturn(value)
Devery { function() } returns value
What does the verify { ... } block do in MockK?
AMocks a function
BChecks if a mocked function was called
CCreates a spy object
DResets mocks
Which MockK function creates a spy that calls real methods unless mocked?
Astubk()
Bmockk()
Cspyk()
Dfakek()
What is the main purpose of using MockK in Android testing?
ATo simulate object behavior for unit tests
BTo handle database queries
CTo manage app navigation
DTo create UI layouts
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.