iPhone 上的单元测试如何工作? [英] How does unit testing on the iPhone work?

查看:11
本文介绍了iPhone 上的单元测试如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否需要为此专门的库,或者我可以创建一个巨大的类来尝试实例化我的项目的每个对象并测试其中的所有方法?理论上是怎么做到的?

Do I need special libraries for this, or can I just create a huge class that trys to instantiate every object of my project and test all the methods in there? How's that done in theory?

推荐答案

如果您的目标是 iPhone OS 2.2 或更高版本,您可以使用与 Xcode 捆绑的 OCUnit 版本.Kailoa Kadano 有 一篇很好的博客文章关于此移动果园.OCUnit 是一个单元测试框架,类似于 Java 世界中著名的 JUnit 框架.

If you're targeting iPhone OS 2.2 or later, you can use the version of OCUnit that's bundled with Xcode. There's a good blog article by Kailoa Kadano about this on Mobile Orchard. OCUnit is a unit testing framework that's similar to the well known JUnit framework from the Java world.

您总是可以通过创建一个简单的测试程序来执行穷人的单元测试",该程序使用 C 头文件 assert.h 中的 assert() 宏或 NSAssert() 宏.这不是开始进行单元测试的可怕方式,但我真的建议最终查看 OCUnit 或其他单元测试框架.

You can always do "poor man's unit testing" by creating a simple test program that uses the assert() macro in the C header assert.h or the NSAssert() macros in Cocoa/Cocoa-touch. That's not a horrible way to get started doing unit testing, but I'd really recommend looking at OCUnit or another unit testing framework eventually.

无论您以何种方式构建单元测试,您都需要在 Xcode 项目中创建一个单独的目标来构建和运行测试.

Which ever way you structure your unit tests, you'll want to create a separate target in your Xcode project to build and run the tests.

这篇关于iPhone 上的单元测试如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆