How to unit tests a private or internal function in Swift?

十年热恋 提交于 2019-12-04 10:29:37

You will not be able to test the private functions. But you can test internal ones. In your test, where you import your framework, eg import MyFramework, change it to:

@testable import MyFramework

I found the answer is we don't test private methods. We put a method private for a reason and it should be used by a public method. I assume whether we test private method, it's better to test the public method that uses the private method.

Another extra explanation I found it here: https://cocoacasts.com/how-to-unit-test-private-methods-in-swift/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!