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

has for my information first setup method will called and invoke the testcaseMethod then tear down will be called. Its teardown before setup, any one advice me on this issue why its teardown before setup.

Kiran
  • 345
  • 1
  • 4
  • 16

2 Answers2

0

Don't put STFail assertions in setUp or tearDown. Nor do you need exception handling; OCUnit will catch and report any exceptions thrown.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • For my setup and tearDown should not thrown the exception! i put STFail to know that [Problem setupProblem]; have done successfully and also for the teardown [Problem teardownproblem]; if this methods are not setup teardown properly it gives me error value for which need not to throw an exception! – Kiran Feb 28 '13 at 04:51
0

You can print the call stack and generally view these exceptions by using the SenTestCaseDidFailNotification:

Example:

@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
bentford
  • 33,038
  • 7
  • 61
  • 57