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

Testing iOS applications

Apr 10, 2017

Download

Software

AnadeaInc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Testing iOS applications

Testing iOS applicationsor how I fell in love with writing tests

Page 2: Testing iOS applications

Where to start from?

Page 3: Testing iOS applications

Types of testing from the developer’s pointof view

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

components)3) Acceptance tests

Page 4: Testing iOS applications

Test with XCTest

Page 5: Testing iOS applications

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)

Page 6: Testing iOS applications

Test with OCMock

Page 7: Testing iOS applications

Integration tests

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

Page 8: Testing iOS applications

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

Page 9: Testing iOS applications

KIF test

Page 10: Testing iOS applications

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.

Page 11: Testing iOS applications

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.

Page 12: Testing iOS applications

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

Page 13: Testing iOS applications
Page 14: Testing iOS applications
Page 15: Testing iOS applications

What to test and when?

Page 16: Testing iOS applications

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 :)

Page 17: Testing iOS applications

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?!)

Page 18: Testing iOS applications

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