Share
Embed
Why we are (not) writing tests in iOS
The reason we still aren't writing tests in iOS
Paul Taykalo
October 27, 2017
Transcript
75 slides
-
Why we are (not) writing tests in iOS apps by
Paul Taykalo, Stanfy Lost in maintenance, by Paul Taykalo, #SE2017 1 -
Plan » Types of projects in IOS » Need for
tests » Reasons why we aren't writing the tets » Bugs vs tests » How not to write tests with success » Selling tests Lost in maintenance, by Paul Taykalo, #SE2017 3 -
Types of projects in iOS Lost in maintenance, by Paul
Taykalo, #SE2017 5 -
Types of projects in iOS » MVP/Pet » Copycat =^.^=
» Mastodon » Hyped Unicorn » Own product/Library Lost in maintenance, by Paul Taykalo, #SE2017 6 -
Hyped Unicorn All frameworks all the Things Hyped Social App
Lost in maintenance, by Paul Taykalo, #SE2017 10 -
Different products Different aproaches Different styles Lost in maintenance, by
Paul Taykalo, #SE2017 12 -
Need for tests » ❌ MVP/Pet/Games » " Copycat »
✅ Mastodon » " Hyped Unicorn » ✅ Own product/Library Lost in maintenance, by Paul Taykalo, #SE2017 14 -
What is the next project you will work on? »
MVP/Pet » Copycat » Mastodon » Hyped Unicorn » Own product/Library Lost in maintenance, by Paul Taykalo, #SE2017 15 -
We don't need tests. We work on the projects with
short lifetime and they're too small for tests — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 16 -
Bugs probability depends on » Lifetime » Time between updates
» User base » Integrations count » Code base/complexity » Team change Lost in maintenance, by Paul Taykalo, #SE2017 19 -
Reason why we should do write tests Lost in maintenance,
by Paul Taykalo, #SE2017 20 -
What tests will we write? 1. UI/Acceptance tests 2. Unit
tests 3. Integration tests 4. Snapshot tests Lost in maintenance, by Paul Taykalo, #SE2017 22 -
UI/Acceptance Tests quality » Overfitting » Orange tests » Hard
to support test data » Complex running flow » ¯\_(ϑ)_/¯ It works on my machine:) Lost in maintenance, by Paul Taykalo, #SE2017 24 -
We aren't writing tests. We were writing tests, but they
were too fragile, and they were breaking for no reason, so we decided not to — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 27 -
Unit tests quality » No modularity - Slow tests »
High overfitting chance » Less tend to be fragile, Have the biggest value » Often SUT is not correctly selected Lost in maintenance, by Paul Taykalo, #SE2017 28 -
Tests are slow. It is way easier to run application
directly and check — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 29 -
Choose your System Under Test Correctly Lost in maintenance, by
Paul Taykalo, #SE2017 30 -
Integration tests quality » Signlentons » Complex tests » Hard
to support » Implementation dependent (fragile) Lost in maintenance, by Paul Taykalo, #SE2017 33 -
It's hard to support tests. Once I change something a
little I need to rewrite a lot of the tests — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 34 -
Snapshot testing » UI only* » Works for components »
Works best with data flow Lost in maintenance, by Paul Taykalo, #SE2017 35 -
Every time new OS released, all my snapshot tests are
broken. It's not worth it — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 36 -
I added tests they didn't help — Unknown programmer Lost
in maintenance, by Paul Taykalo, #SE2017 40 -
Tests are not a cure Tests are the insurance Lost
in maintenance, by Paul Taykalo, #SE2017 41 -
I spent weeks trying to test UI and failed all
deadlines — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 42 -
Some parts are really hard to test Deal with it
Lost in maintenance, by Paul Taykalo, #SE2017 43 -
There are a lot of tests, but the code doesn't
seem to be better — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 44 -
Tests won't make your code significantly better* Lost in maintenance,
by Paul Taykalo, #SE2017 45 -
You still can write ugly code Lost in maintenance, by
Paul Taykalo, #SE2017 46 -
Some tips for those who doesn't write tests Lost in
maintenance, by Paul Taykalo, #SE2017 47 -
Don't show/require all data YAGNI struct User { let id:
String let name: String let address: String let friends: [User] let dogName: String? let hairStyle: HairStyle ... } Lost in maintenance, by Paul Taykalo, #SE2017 48 -
Own Data layer Layer things out class AppApi { func
getUser(by id: String) -> SignalProducer<User, AppApiError> } Lost in maintenance, by Paul Taykalo, #SE2017 49 -
Layer things out enum AppApiError: Error { case userNotLoggedIn case
serverFeelsBad case subscriptionEnded case unknown(NetworkError) // } Lost in maintenance, by Paul Taykalo, #SE2017 50 -
Layer things out // Struct for showing error imeediately to
the user struct UserError { let title: String let message: String // just in some really rare cases let underlyingError: Error } Lost in maintenance, by Paul Taykalo, #SE2017 51 -
Don't allow invalid data struct UserForm { let id: String?
let name: String? let lastName: String? } struct User { let id: String let name: String let lastName: String } Lost in maintenance, by Paul Taykalo, #SE2017 52 -
Isolate Order Dependent Code dataSource.addItems(["1","2","3") tableView.insertItems(at indexPaths:[IndexPath]) tableView.deleteItems(at indexPaths:[]) tableView.reloadData()
Lost in maintenance, by Paul Taykalo, #SE2017 53 -
Semantic meaning if itemsCount > 4 if user.rating > 200
&& user.userName.isNotEmpty if view.tag == 13 Lost in maintenance, by Paul Taykalo, #SE2017 54 -
Linear code loginUser(onSuccess: { user in getAllImages(for: user, onSuccess: {
images is verify(images: images, onSuccess: { verified, unverified is verifyDeletion(images: unverified, onSuccess: { shouldDelete in }, onFailure: { // TODO Handle it print(error) }) }, onFailure: { // TODO Handle it print(error) }) }, onFailure: { // TODO Handle it print(error) }) }, onFailure: { // TODO Handle it print(error) }) Lost in maintenance, by Paul Taykalo, #SE2017 56 -
Linear code loggeduserRequest .flatMap(.latest, { user in getAllimages(for: user)}) .flatMap(.latest,
{ images in verify(images: images)}) .flatMap { verified, unverified in askForDeletion(images: unverified)} .filter { shouldDelete in deleteImages(shouldDelete) } Lost in maintenance, by Paul Taykalo, #SE2017 57 -
Decrease amount of possible states » Optionals » BFO (Object)
» Exponential number of states » Mutability Lost in maintenance, by Paul Taykalo, #SE2017 58 -
Some tips for those who doesn't write tests » Don't
show/require all data » Layer things out » Don't allow invalid data » Semantic meaning » Linear flow » Decrease amount of possible states Lost in maintenance, by Paul Taykalo, #SE2017 59 -
How (not) to fail adding tests Lost in maintenance, by
Paul Taykalo, #SE2017 60 -
How (not) to fail adding tests » Read a lot
about testing and types of testing » Try to test-first, try to test-last » Determine your core » Isolate features and test them » Start with Unit tests » For Custom UI you can run snapshot testing Lost in maintenance, by Paul Taykalo, #SE2017 61 -
- I won't pay additionally for tests - But there'll
be bugs - They'll be there even if you write tests! Lost in maintenance, by Paul Taykalo, #SE2017 63 -
I'm not paying you for bug fixes! — angry customer
Lost in maintenance, by Paul Taykalo, #SE2017 66 -
How not to go into this conversation Lost in maintenance,
by Paul Taykalo, #SE2017 67 -
How not to go into this conversation » React fast
» Notify client about changes » Have support plan (include support as an option) » Always assume your code is not working -- prove it otherwise! » It's not fixed until it's checked (see tests) » Acceptance rules (Hard case) Lost in maintenance, by Paul Taykalo, #SE2017 68 -
There are many ways to write an application. We're not
building spaceships, you know? — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 69 -
Why we are (not) writing tests in iOS apps by
Paul Taykalo, Stanfy @TT_Kilew Lost in maintenance, by Paul Taykalo, #SE2017 71 -
Bonus Building a Swift Quiz App with TDD and Modular
Design https://goo.gl/cUzTkr Lost in maintenance, by Paul Taykalo, #SE2017 73 -
Links http://merowing.info/2017/01/testing-ios-apps/ https://www.swiftbysundell.com/posts/testing-swift-code- that-uses-system-singletons-in-3-easy-steps? utmcontent=buffer1765f&utmmedium=social&utmsource=twitter.co m&utmcampaign=buffer https://www.joelonsoftware.com/2001/07/31/hard-assed-bug- fixin/ Lost in
maintenance, by Paul Taykalo, #SE2017 74