本文介绍了如何测试使用UIKit的iOS库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为使用UIKit的iOS应用程序创建一个库。此外,我想为这个库创建单元测试。不幸的是,由于UIKit( [UIFont systemFontOfSize:12.0] ),我的测试不起作用。

I would like to create a library for iOS applications which uses UIKit. Furthermore I would like to create unit tests for this library. Unfortunately my tests do not work because of UIKit ([UIFont systemFontOfSize:12.0] to be precise).

根据有两种类型的测试用例:逻辑测试和应用程序测试。应用程序测试似乎是涉及UIKit相关内容的测试的正确类型,但我没有找到如何为库设置应用程序测试。有没有人遇到过同样的问题并能解决它?

According to Apple's Unit Testing Guide there are two types of test cases: logic tests and application tests. Application tests seem to be the correct type for tests involving UIKit related stuff but I did not find out about how to set up application tests for libraries. Has anybody ever had the same problem and was able to solve it?

非常感谢!

推荐答案

我找到了解决方案。您必须向项目中添加一个新目标,它只是一个空的应用程序。然后使用该应用程序作为测试主机,按照以下常规应用程序执行此操作的说明:

I found a solution to this. You must add a new target to your project that is simply an empty application. Then use that application as your test host following the instructions for doing this with a regular application like here:

这篇关于如何测试使用UIKit的iOS库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:17