English 中文(简体)
如何使用Xcode 4和OCUnit运行应用程序测试?
原标题:how to run application testing using Xcode 4 and OCUnit?

我正在使用OCUnit编写单元测试,我尝试了GHUnit,但它不适合我的情况。

我确实想运行应用程序测试,因为我的代码严重依赖于我的ApplicationDelegate实例。但我只能弄清楚如何运行逻辑测试,而不能弄清楚应用程序测试。

这是来自模板的测试代码示例,但我的测试失败(没有应用程序委托)或根本没有运行测试代码。

- (void) testAppDelegate {

    id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];
    STAssertNotNil(yourApplicationDelegate, @"UIApplication failed to find the AppDelegate");

}

我发现了苹果公司关于如何设置测试的指南,但它不适用于Xcode 4

最佳回答

found answer here how to implement application tests in xcode4?

假设您有一个名为“MyApp”的应用程序目标

  1. Add a new target of type "other/Cocoa Unit Testing Bundle" to the project e.g "MyAppTesting". Here all Unit test files are located.
  2. Go to MyAppTesting Build Phases and add MyApp as Target Dependency. This assures that MyApp is build before building the MyAppTesting target.
  3. Open the Build Settings of MyAppTesting and change
    • Bundle Loader: $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp
    • Test host: $(BUNDLE_LOADER)
    That causes the tests to run within MyApp.
  4. Open the Build Settings of MyApp and change
    • Symbols Hidden by default: NO (for both)
    • Strip debug Symbols during Copy: Debug:NO
    By doing so you do not have to include every .m-file into the test target.
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签