科特林/母语 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:Kotlin/NativeKotlin/JSThis 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的单元测试中模拟对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!