2013-02-27 67 views
1
- (void)setUp 
{ 
    [super setUp]; 
    @try { 
     [Problem setupProblem]; 
    } 
    @catch (NSException *exception) { 

     NSLog(@"exception Caught %@: %@", [exception name], [exception reason]); 
     STFail(@"Should Pass, no exception is expected. Exception <%@>", exception); 
    } 
} 

- (void)tearDown 
{ 
    // Tear-down code here. 

    @try { 
     [Problem teardownproblem]; 
    } 
    @catch (NSException* exception) { 

     NSLog(@"exception Caught %@: %@", [exception name], [exception reason]); 
    STFail(@"Should Pass, no exception is expected. Exception <%@>", exception); 
} 
    } 
-(void)testGetComponentNil{ 

    id testComponet = (id<Solution>)[Problem getComponent:nil]; 
      STAssertNil(testComponet, @"Return Nil"); 
STAssertNotNil(id<Solution>[problem getComponent:@"Problem"], @""); 

} 


exception Caught NSInternalInconsistencyException: Cannot teardownProblem() before setupProblem() 

<Cannot teardownProblem() before setupProblem().> 

已經爲我的信息第一次設置方法將調用並調用testcaseMethod然後拆除將被稱爲。它在安裝前拆卸, 任何人都可以在這個問題上給我建議,爲什麼在安裝之前拆卸它。異常提出的設置和拆卸OCUnit測試用例

回答

0

不要在setUp或tearDown中放置STFail斷言。你也不需要異常處理; OCUnit將捕獲並報告拋出的任何異常。

+0

對於我的建立和拆除不應該拋出的異常!我讓STFail知道[Problem setupProblem];已經成功地完成了,也是爲了拆解[Problem teardownproblem];如果這種方法沒有設置拆卸正確,它給了我錯誤的值,無需拋出異常! – Kiran 2013-02-28 04:51:44

0

可以打印調用堆棧,一般使用SenTestCaseDidFailNotification查看這些例外情況:

例子:

@implementation TestCase 
- (void)setUp 
{ 
    [super setUp]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFailTest:) name:SenTestCaseDidFailNotification object:nil]; 
} 

- (void)didFailTest:(NSNotification *)notification 
{ 
    SenTestCaseRun *theRun = notification.object; 

    for (NSException *exception in theRun.exceptions) { 
     NSLog(@"Exception: %@ - %@", exception.name, exception.reason); 
     NSLog(@"\n\nCALL STACK: %@\n\n",exception.callStackSymbols); 
    } 
} 
@end 
相關問題