Kotlin Multiplatform:如何在iOS的单元测试中模拟对象 [英] Kotlin Multiplatform: How to mock objects in a unit test for iOS
问题描述
我正在为iOS/Android开发Kotlin多平台(KMP)库.我已经为JVM编写了一些单元测试,为此我使用 MockK 创建间谍和模拟,但MockK不支持Kotlin完全原生.
因此,我想知道其他从事KMP项目的人如何为iOS平台编写单元测试.一个例子将不胜感激.
当前,MockK不支持Kotlin/Native或Kotlin/JS.但是,两者都被作为重要项目在项目待办事项中:>
鉴于模拟库在很大程度上依赖于语言功能(例如反射),这是一个很大的挑战,而Kotlin多平台还没有完全支持这种语言功能(如果没有针对特定平台的大量解决方法,甚至可能无法支持该功能).
这当然不会阻止您编写自定义模拟类并验证您在其中设置的状态,其中的测试将能够在所有平台上运行.
I'm working on a Kotlin-multiplatform (KMP) library for iOS / Android. I have written some unit tests for JVM, for which I use MockK to create spies and mocks, but MockK doesn't support Kotlin native fully yet.
Therefore, I was wondering how others working on KMP projects write unit tests for the iOS platform. An example would be really appreciated.
Currently, MockK does not support Kotlin/Native or Kotlin/JS. However, both are placed as important items on the project backlog:
This is a big challenge given that a mocking library relies heavily on language features such as reflection which are not fully supported yet on Kotlin multiplatform (and possibly even can't be supported without considerable workarounds for specific platforms).
This does not prevent you from writing custom mock classes and verify states you set therein, of course, of which the tests will be able to run on all platforms.
这篇关于Kotlin Multiplatform:如何在iOS的单元测试中模拟对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!