https://github.com/mwoss/mockk-examples
https://github.com/mwoss/mockk-examples
example kotlin mock mockk testing
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mwoss/mockk-examples
- Owner: mwoss
- Created: 2021-04-12T10:23:06.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T10:25:52.000Z (almost 5 years ago)
- Last Synced: 2025-01-24T08:23:19.495Z (about 1 year ago)
- Topics: example, kotlin, mock, mockk, testing
- Language: Kotlin
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mocking examples using Mockk (Kotlin)
This repository contains a dozen or so mocking examples using [Mockk](https://github.com/mockk/mockk) library.
Repository contains only basic examples which are mostly used in day to day work. For more advanced topics please check official [Mockk documentation](https://mockk.io/)
All examples can be found in test directory: `src/test/kotlin`
Topics covered in examples:
* types of Mocks (MockK, SpyK, RelaxedMock)
* object and static class mocking
* partial matching (matchers)
* hierarchical mocking
* slot capturing
* verification (verify block)
* private method mocking
* constructor mocking
Also, I highly recommend reading [Unraveling MockK’s black magic](https://chao2zhang.medium.com/unraveling-mockks-black-magic-e725c61ed9dd) article in some point of your journey with Mockk.
It will allow you to understand how Mockk works underneath. This should help you to write better tests/mocks and quickly find a root cause of failing tests.