18
Testing iOS applications or how I fell in love with writing tests

Testing iOS applications

Embed Size (px)

Citation preview

Testing iOS applicationsor how I fell in love with writing tests

Where to start from?

Types of testing from the developer’s pointof view

1) Module testing (Unit tests)2) Integration testing (testing of

components)3) Acceptance tests

Test with XCTest

Mocks and Stubs in unit tests

1) OCMock (http://ocmock.org/) 2) Mockito (https://github.com/jonreid/OCMockito)3) AFHTTPStubs (https://github.

com/AliSoftware/OHHTTPStubs)

Test with OCMock

Integration tests

1) Calabash2) KIF3) UIAutomation4) Frank5) XCode UI tests (New!!!)

Why KIF?

1) Objective-C syntax2) It can be added via pod into current or new test target3) Opportunity to use OCMock stubs and expects

KIF test

The advantages

1) One test executes several actions at once. Therefore you can quickly cover a large amount of code with tests.

2) It saves your time when it is necessary to run the app in order to check how the main functions operate.

3) It is easy to catch minor things, especially the ones at switching between screens that are difficult to check with unit-tests.

The disadvantages

1) If the test scenario fails before completion, the next ones will not pass because the application is not restarted.

2) It uses a private API, so some functions do not work after updating iOS.3) Tests run quite slowly.4) Tied to the simulator (tests may not pass if displaying the keyboard is

turned off, when system screens pop up, etc.)5) Connected to the accessibility labels.

Tools for determining the coverage

1) Frankencover (http://frankencover.it/)

+ visualization (!!!), quantitative evaluation, reports

- does not support Swift code, depends on the xcode data

2) Xcode (integrated coverage)

Built-in, supported by the Apple developers

What to test and when?

Why is it great to write the test first andthen the code?

1) It allows to think through the structure of the class in more detail2) You may describe possible variations of the method's behavior in the tests

and then write the code that meets all the requirements3) You have to split the methods into the smaller ones for testing4) Because it is so difficult to make yourself to write the tests afterwards :)

It is difficult to use when

1) a new framework / library is used and so the end result is not known2) there is not much logic and a lot of representation (animations, layouts)3) very small application - tight schedule (but what if it comes back to us one

day?!)

Useful links

1) http://iosunittesting.com/2) Graham Lee - Test-Driven iOS Development3) Kent Beck's Books4) http://frankencover.it/5) http://ocmock.org/

Visit our blog for more great posts: anadea.info/blog