Xcode iOS 测试套件 NSLog 输出丢失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26768855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:06:10  来源:igfitidea点击:

Xcode iOS testsuite NSLog output missing

iosxcodeunit-testingoutput

提问by user1165560

I'm developing an iOS app using Xcode 6 and am trying to run a test suite in Xcode. I can run the test but I don't see where my NSLogstatements output. They are not in the output panel.

我正在使用 Xcode 6 开发 iOS 应用程序,并尝试在 Xcode 中运行测试套件。我可以运行测试,但我看不到我的NSLog语句输出在哪里。它们不在输出面板中。

How do I find the output?

我如何找到输出?

@interface ISTest : XCTestCase
@end

@implement ISTest
- (void) setUp {
    [super setUp];
}

- (void) tearDown {
    [super tearDown];
}

- (void) testExample {
    NSLog(@"Where does this go???");
}

- (void) testPerformanceExample {
    [self measureBlock^{
    }];
}
@end

回答by JAL

Check console in the debugging area (the lower view) in Xcode. To open this view, click the square button with the blue rectangle on the bottom in the top-right corner of Xcode.

检查 Xcode 调试区域(下方视图)中的控制台。要打开此视图,请单击 Xcode 右上角底部带有蓝色矩形的方形按钮。

Edit: Why the downvote? Log statements appear in the debugging area for me.

编辑:为什么投反对票?日志语句出现在我的调试区。

Test:

测试:

- (void)testLoginViewControllerViewExists {
    NSLog(@"Testing Login View Controller");
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    CSLoginViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:
                                      @"loginVC"];
    XCTAssertNotNil([loginVC view], @"loginVC should contain a view");
}

Output:

输出:

Test Case '-[AppTests testLoginViewControllerViewExists]' started.
2014-11-06 15:52:00.175 App[14870:2071450] Testing Login View Controller
Test Case '-[AppTests testLoginViewControllerViewExists]' passed (0.001 seconds).

回答by Abizern

Log output in tests does not go to the console.

测试中的日志输出不会进入控制台。

If you want to see your logs, they are in the build output.

如果您想查看日志,它们在构建输出中。

回答by C. Kontos

If you want to see your messages or your strings in your tests being printed on the output console use printfand not NSLog

如果您想在输出控制台上打印测试中的消息或字符串,请使用printf而不是NSLog

Example: printf("%s", [yourNSString UTF8String]);

例子: printf("%s", [yourNSString UTF8String]);