简体   繁体   English

Swift单元测试用例-模拟框架

[英]Swift Unit test case - Mock framwork

I want to use mock framework for swift language in iOS. 我想将模拟框架用于iOS中的快速语言。 I have used OCMock framework for Objective C, But same was not working in swift. 我已经为目标C使用了OCMock框架,但是同样不能迅速进行。 So, I need proper frameworks for handling mock object in swift. 因此,我需要适当的框架来快速处理模拟对象。

It's common to have to implement 'mocking' through fakes or test doubles in Swift. 在Swift中,必须通过伪造或双打测试来实现“模拟”。 Either through implementing protocols or subclassing in your tests. 通过实施协议或在测试中进行子类化。

This kind of mocking leads towards design patterns like dependency injection where you can test portions in isolation. 这种模拟导致了诸如依赖注入的设计模式,您可以在其中独立地测试部分。

Things like OCMock or Kiwi relied on objective-c's runtime. 诸如OCMock或Kiwi之类的东西都依赖Objective-C的运行时。 Swift has yet to implement reflection as it is still working out its ABI stability. Swift仍在研究其ABI稳定性,因此尚未实施反射。 Until that comes, manually implementing mocks is the way to go. 在此之前,手动实现模拟是必经之路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM