Let's imagine a screen with two buttons and we want to touch the second one, the UIquery code of the button is
[[[app button] index:1] touch];
If this code is not correct or the button is no present on the screen the application which run the tests will crash, but if we set the expectation before the interaction
[expectThat([app button] index:1]) should:be(YES)];
[[[app button] index:1] touch];
as the expectation will not be satisfied the execution of this spec will finish at this point but it won't finish the execution of the whole test application. It will continue with the next spec.
A more elaborated implementation could be
BOOL existElement;
@try {
existElement = [[[[app button] index:1] should] exist];
}
@catch (NSException *exception) {
NSLog(@"EXCEPTION CAUSED BY: %@", [NSThread callStackSymbols]);
}
@finally {
[expectThat(existElement) should:be(YES)];
}



