【问题标题】:Xcode Unit Tests - Can't add new test, because it isn't runXcode 单元测试 - 无法添加新测试,因为它没有运行
【发布时间】:2014-08-03 02:47:05
【问题描述】:

我正在学习 Xcode 中的单元测试。 Xcode 为我生成了模板,但是当我添加一个新的测试方法时它没有运行。 为什么?我已经疯了。我不知道为什么,我找不到任何解决方案。

    #import <XCTest/XCTest.h>

@interface TesttestTests : XCTestCase

@end

@implementation TesttestTests

 -(void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

 -(void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

 -(void)testExample
{
    XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}

 -(void)newtest{
    XCTAssert(false, @"This'll be false");
}

所以我添加了最后一个方法,但我的测试类无法识别它。为什么?

【问题讨论】:

    标签: ios xcode unit-testing methods


    【解决方案1】:

    为了让 Xcode 识别它是一个测试,你需要以“test”开头测试方法的名字。试试这个:

    - (void)testNew {
        XCTAssert(false, @"This'll be false");
    }
    

    【讨论】:

    • 非常感谢。为什么苹果没有在他们的文档中写这个? :D
    • 没问题,很乐意提供帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 2019-04-15
    • 2011-08-29
    • 2021-08-23
    • 2016-03-23
    • 2014-09-19
    • 2013-09-27
    相关资源
    最近更新 更多