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().>

对于我的信息,第一个 setup 方法将被调用并调用 testcaseMethod,然后会调用 tear down。它在安装前拆解,任何人都在这个问题上建议我为什么在安装前拆解。

4

2 回答 2

0

不要将 STFail 断言放在 setUp 或 tearDown 中。你也不需要异常处理;OCUnit 将捕获并报告任何抛出的异常。

于 2013-02-28T04:26:49.437 回答
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
于 2013-05-09T21:51:29.860 回答