【发布时间】:2010-09-06 13:32:36
【问题描述】:
我在以下创建的最小项目中有以下最小测试用例 GHUnit 自述文件:
#import <GHUnitIOS/GHUnitIOS.h>
#import <UIKit/UIKit.h>
@interface MyTest : GHTestCase { }
@end
@implementation MyTest
- (BOOL)shouldRunOnMainThread {
return YES;
}
- (void)testFoo {
UITableViewCell *cell =
[[UITableViewCell alloc] initWithStyle:UITableViewStylePlain
reuseIdentifier:@"foo"];
NSLog(@"cell: %@", cell);
NSLog(@"cell.textLabel: %@", cell.textLabel);
}
@end
当我在 Xcode 的模拟器中使用 Build and Run 时,它运行良好。然而,当我 在终端中运行以下命令:
GHUNIT_CLI=1 xcodebuild -target Tests -configuration Debug -sdk iphonesimulator4.0 build
我得到这个输出:
Running: /Users/<user>/Desktop/tmp/TestApp/build/Debug-iphonesimulator/Tests.app/Tests -RegisterForSystemEvents
Tests(39346) malloc: protecting edges
Tests(39346) malloc: recording malloc stacks to disk using standard recorder
Tests(39346) malloc: enabling scribbling to detect mods to free blocks
Tests(39346) malloc: process 39249 no longer exists, stack logs deleted from /tmp/stack-logs.39249.Tests.ac1JfL.index
Tests(39346) malloc: stack logs being written into /tmp/stack-logs.39346.Tests.t8LG4p.index
Test Suite 'Tests' started.
MyTest/testFoo 2010-09-06 23:24:25.006 Tests[39346:903] cell: <UITableViewCell: 0x5a6d190; frame = (0 0; 320 44); layer = <CALayer: 0x5a6d390>>
RunTests.sh: line 28: 39346 Trace/BPT trap $RUN_CMD
Command /bin/sh failed with exit code 133
Command /bin/sh failed with exit code 133
** BUILD FAILED **
OCUnit 也会发生这种“Trace/BPT Trap”事情,我希望 GHUnit 会解决它,但它不在命令行上。任何人都知道什么 是关于?它似乎与在你不是的上下文中使用 UIKit 有关 应该的,但我不明白到底是什么限制。
【问题讨论】:
-
啊,我添加了更多代码并发现当我在命令行上运行时
[NSApplication sharedApplication]为空;我认为这与此有关。那么有没有一种简单的方法可以在不运行模拟器的情况下运行使用 UIKit 类的单元测试?
标签: objective-c cocoa-touch unit-testing ocunit