刚刚开始在Xcode 5中使用XCTest((Xcode Version 5.0.2 [5A3005])。我制作了一个示例测试文件,我在其中测试true是否为真。它工作正常,测试按预期传递。当我添加时在断言前面有一个NSLog
语句,测试失败并显示消息“test_case没有完成”,其中“test_case”是我的测试方法名称(在我的情况下是testTrue)。
这是失败案例中的test1.m
。失败和工作之间的唯一区别是失败的案例在测试方法中有NSLog
。 (当我在setUp和/或tearDown方法中尝试NSLog
时,它也失败了。)
#import <XCTest/XCTest.h>
@interface test1 : XCTestCase
@end
@implementation test1
- (void)setUp
{
[super setUp];
// Put setup code here; it will be run once, before the first test case.
}
- (void)tearDown
{
// Put teardown code here; it will be run once, after the last test case.
[super tearDown];
}
- (void)testTrue
{
// if I comment out following NSLog the test works
NSLog(@"test1: testTrue");
XCTAssertTrue(true, @"true is not true");
}
@end
以下是故障情况下Log Navigator的具体输出:
Test Suite 'All tests' started at 2014-02-07 21:31:42 +0000
Test Suite 'xct-test1Tests.xctest' started at 2014-02-07 21:31:42 +0000
Test Suite 'test1' started at 2014-02-07 21:31:42 +0000
Test Case '-[test1 testTrue]' started.
testTrue did not finish
以下是相同的输出(当我不包含NSLog
语句时):
Test Suite 'All tests' started at 2014-02-07 21:38:59 +0000
Test Suite 'xct-test1Tests.xctest' started at 2014-02-07 21:38:59 +0000
Test Suite 'test1' started at 2014-02-07 21:38:59 +0000
Test Case '-[test1 testTrue]' started.
Test Case '-[test1 testTrue]' passed (0.000 seconds).
Test Suite 'test1' finished at 2014-02-07 21:38:59 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
Test Suite 'xct-test1Tests.xctest' finished at 2014-02-07 21:38:59 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
Test Suite 'All tests' finished at 2014-02-07 21:38:59 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
那么为什么我的NSLog
中的测试失败了呢?提前感谢您的帮助......