SenTesting test after the first STAssert test

Is there a way to stop the execution of the iOS unit test after the failure of the first STAssert?

For example, if I have several STAsserts:

STAssertTrue([myobject succeeded], @"failed");
STAssertNotNil(foo,@"bar");

I would really like it if Xcode just stopped running the test after the first failure. Any way to do this?

+5
source share
3 answers

If you have an exception checkpoint for all exceptions, Xcode will discard the debugger on the first failed test. If you perform tests manually in Xcode, this may be acceptable.

To configure an exception checkpoint in Xcode 4 +

  • View> Navigators> Show breakpoint navigator
  • "+" " ", " "
  • "" .

Xcode , .

+1

, STAssert .

- (void)failWithException:(NSException *)anException{
  [super failWithException:anException];
  NSAssert(false, @"An assertion has failed");
}
0

SenTestCasehas a method -[SenTestCase raiseAfterFailure]that causes STAssert...an exception to be thrown at the end, preventing the execution of the next line in the test.

You can do this based on a test:

- (void)testSomeStuff
{
    [self raiseAfterFailure];
    STAssertTrue([myobject succeeded], @"failed");
    STAssertNotNil(foo,@"bar");
}

Or at the class level:

- (void)setUp
{
    [super setUp];
    [self raiseAfterFailure];
}
0
source

All Articles