3

刚开始在 Xcode 5 中使用 XCTest((Xcode 版本 5.0.2 [5A3005])。我制作了一个示例测试文件,在其中测试 true 为真。它可以正常工作并且测试按预期通过。当我NSLog在在断言的前面,测试失败并显示消息“test_case 未完成”,其中“test_case”是我的测试方法名称(在我的情况下为 testTrue)。

这是test1.m失败的情况。失败和工作之间的唯一区别是失败案例NSLog在测试方法中有一个。(当我尝试NSLog使用 setUp 和/或 tearDown 方法时,它也会失败。)

#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

以下是失败案例中日志导航器的具体输出:

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进去的时候会失败呢?在此先感谢您的帮助...

4

0 回答 0