1

我是 iPhone 开发的新手。我已经集成了框架 GHUnitIOS 来测试我的应用程序。但我还没有找到有关如何实施单元测试的文档(这是我第一次进行单元测试)。

有人可以帮助我从 GHUnit、文档、示例、解释开始吗?

4

2 回答 2

4

Here is how you configure a new target to run tests with GHUnit:

  • Download the GHUnitIOS framework. Note the name, don't download the one for OS X.

  • Add a new target to your project.

  • Add the following frameworks: GHUnitIOS.framework, CoreGraphics.framework, Foundation.framework, UIKit.framework, CoreLocation.framework

  • In Build Settings > Other Linker Flags add -ObjC and -all_load

  • Edit the ...-Info.plist for your target with a text editor and comment the following:

<!--
<key>NSMainNibFile</key>
<string>MainWindow</string>
-->
  • Add the GHUnitIOSTestMain.m file into your project.
  • In the build settings of your new target, remove the file main.m.
  • In the .pch file for your new target add #import <GHUnitIOS/GHUnit.h>

Now add a test:

// this import is already in the pch
// #import <GHUnitIOS/GHUnit.h>

@interface MyTest : GHTestCase { }
@end


@implementation MyTest

- (void)testFoo {
    // assert that foo is not nil
    GHAssertNotNULL(foo, @"foo was nil");
}

@end

Your test methods should start with test. There are other methods you can add like setUp, tearDown, setUpClass, tearDownClass, and a number of GHAssertxxx assertions.

于 2011-04-20T15:08:11.660 回答
0

不了解 GHUnit,但 PragPub 使用 Google 工具箱有一篇关于 iPhone 上 TDD 的好文章 - 请参阅http://www.pragprog.com/magazines/2010-07/tdd-on-iphone-diy

于 2011-04-20T11:56:47.253 回答