我在创建一个最小化项目以下最低测试用例以下 的GHUnit自述:为什么从单元测试中使用UITableViewCell会导致Trace/BPT陷阱?
#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模拟器运行正常。然而,当我 运行在终端下面的命令:
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 **
这种“跟踪/ BPT陷阱”的事情用的OCUnit发生过了,我希望GHUnit 可以解决它,但它不在命令行上。任何人都知道这是什么 ?这似乎与从你不是 应该的上下文中使用UIKit有关,但我不明白限制是什么。
啊,我添加了一些代码,并发现当我在命令行上运行时,[NSApplication sharedApplication]为空;我认为这与此有关。那么是否有一种简单的方法来运行使用UIKit类而不运行模拟器的单元测试? – 2010-09-06 13:57:07