square/KIF — pull request #180 by bnickel (2012-12-14 21:05:27+00:00)
Title: Add ability to run KIF inside of standard unit testing targets

This pull request adds the ability to run KIF inside a standard unit testing target instead of using a duplicated target. Test steps run in a subclass of SenTestCase and run sequentially on the main thread using `-[NSRunLoop runUntilDate:]` to prevent from blocking.

This provides a variety of advantages over the existing test controller:
- There is no need to duplicate a target. The existing unit testing target that gets auto-generated works fine by simply modifying the loader flags and linking the libraries. New targets are also easy to configure.
- Errors are displayed on the line they occurred on in inside the test.

![Screen Shot 2012-12-14 at 1 54 36 PM](https://f.cloud.github.com/assets/662837/14226/a26ee64e-4630-11e2-98f3-eea952f63359.png)

- Pausing the debugger allows you to see the current test thats executing in context and dive down.

![Screen Shot 2012-12-14 at 1 55 37 PM](https://f.cloud.github.com/assets/662837/14221/7ee90f2e-4630-11e2-84d1-265245665c50.png)

- Multistep tests are easier to assemble and do not need to be grouped in an array. In the below example, a step is executed to wait for a view to appear. The view is immediately consumed with a logic block, and a second step is executed based on the information obtained.

- (void)clearTextFromViewWithAccessibilityLabel:(NSString *)label traits:(UIAccessibilityTraits)traits
{
[self waitForViewWithAccessibilityLabel:label traits:traits];

UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:label accessibilityValue:nil traits:traits];

NSMutableString *text = [NSMutableString string];
for (NSInteger i = 0; i < element.accessibilityValue.length; i ++) {
[text appendString:@"\b"];
}

[self enterText:text intoViewWithAccessibilityLabel:label traits:UIAccessibilityTraitNone expectedResult:@""];
}

- Steps can be added before and after each test or each class to set up the environment. This way you can avoid having to log out and in repeatedly in complex apps:

- (void)beforeAll
{
[tester tapViewWithAccessibilityLabel:@"Basic Calculator" traits:UIAccessibilityTraitButton];
}

- (void)afterAll
{
[tester tapViewWithAccessibilityLabel:@"Home" traits:UIAccessibilityTraitButton];
}

- Individual tests can be disabled and enabled in Xcode.

![Screen Shot 2012-12-14 at 2 07 52 PM](https://f.cloud.github.com/assets/662837/14239/805b9556-4631-11e2-82be-9eb28224b7d2.png)

- The setup process for CI would be the same as for unit testing.
- I find it to be more readable.