2014-06-12 71 views
1

我正在學習Xcode中的單元測試。 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"); 
} 

所以我添加了最後一個方法,但我的測試類無法識別它。爲什麼?

回答

1

爲了讓Xcode認識到它是一個測試,您需要使用「test」開始測試方法的名稱。試試這個:

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

非常感謝。爲什麼蘋果沒有在他們的文檔中寫這個? :D – user3621033

+0

沒問題,很樂意幫忙。 – Mike

相關問題