UI Testing with KIF

With KIF, you can easily perform UI tests.

platform "SomeProjTests", :exclusive => true do
  pod "KIF"

And in SomeProjTests.m,

#import <KIF.h>

[tester longPressViewWithAccessibilityLabel:@"Label" value:nil duration:0.5f];
[tester tapViewWithAccessibilityLabel:@"Edit"]; // `UIMenu` Edit
[tester enterTextIntoCurrentFirstResponder:@"Hi! Test!"];
[tester tapViewWithAccessibilityLabel:@"return"]; // Keyboard return

Note that Accessibility Label is a text you can see (literally) in every UI elements. (e.g. For label which have text “Label”, its accessibility label is “Label”. For button “Edit”, its accessibility label is “Edit”.)

Using accessibility labels, you can perform UI tests as above.

You can see the result in following Vine.


Is it difficult? #

Definitely No. You just need to write one pod in Podfile while appium requires some setups. There are no prerequisites.

You can tap a view in one-line.

[test tapViewWithAccessibilityLabel:@"Edit"];

If the view does not exist, simply the test fails. Really simple.

Is the development active? #

Yes. The last commit is 4 days ago. (2014/09/13)

The project have started since 2011. You can find the code frequency here.

It seems to be hard to maintain UI tests in a real project? #

It’s true. User interfaces are often changed. And so test cases should be changed then.
It is hard to maintain perfect UI tests for real projects.

However, there are some cases which can leverage UI tests 100%.
I recommend using UI tests in following cases.

UI Component Project (UI Library) #

Just put some views in a main ViewController for test cases. It is like fixture. So the test won’t be broken.

Gesture Recognizers #

When you put tons of gesture recognizers, you must be encouraged to write tests for them.

Handling variety of gesture recognizers used to be difficult. You can easily create conflict of gesture.

It should be proven that you do not break the recognizers in automated tests. Otherwise you will get fear of making some change about gestures.

References #


Now read this

Adopt Protocol Buffers instead of JSON

Protocol Buffers are a data interchange format used in Google. (also developed by Google) It looks like as follows. package main; message Book { required string title = 1; required int32 page_number = 2; required string author_name = 3;... Continue →