Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why we are (not) writing tests in iOS

Why we are (not) writing tests in iOS

The reason we still aren't writing tests in iOS

Paul Taykalo

October 27, 2017
Tweet

More Decks by Paul Taykalo

Other Decks in Programming

Transcript

  1. Why we are (not) writing tests in iOS apps by

    Paul Taykalo, Stanfy Lost in maintenance, by Paul Taykalo, #SE2017 1
  2. 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
  3. Types of projects in iOS » MVP/Pet » Copycat =^.^=

    » Mastodon » Hyped Unicorn » Own product/Library Lost in maintenance, by Paul Taykalo, #SE2017 6
  4. Hyped Unicorn All frameworks all the Things Hyped Social App

    Lost in maintenance, by Paul Taykalo, #SE2017 10
  5. Need for tests » ❌ MVP/Pet/Games » " Copycat »

    ✅ Mastodon » " Hyped Unicorn » ✅ Own product/Library Lost in maintenance, by Paul Taykalo, #SE2017 14
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. Tests are slow. It is way easier to run application

    directly and check — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 29
  14. Integration tests quality » Signlentons » Complex tests » Hard

    to support » Implementation dependent (fragile) Lost in maintenance, by Paul Taykalo, #SE2017 33
  15. 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
  16. Snapshot testing » UI only* » Works for components »

    Works best with data flow Lost in maintenance, by Paul Taykalo, #SE2017 35
  17. 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
  18. I added tests they didn't help — Unknown programmer Lost

    in maintenance, by Paul Taykalo, #SE2017 40
  19. Tests are not a cure Tests are the insurance Lost

    in maintenance, by Paul Taykalo, #SE2017 41
  20. I spent weeks trying to test UI and failed all

    deadlines — Unknown programmer Lost in maintenance, by Paul Taykalo, #SE2017 42
  21. Some parts are really hard to test Deal with it

    Lost in maintenance, by Paul Taykalo, #SE2017 43
  22. 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
  23. Some tips for those who doesn't write tests Lost in

    maintenance, by Paul Taykalo, #SE2017 47
  24. 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
  25. Own Data layer Layer things out class AppApi { func

    getUser(by id: String) -> SignalProducer<User, AppApiError> } Lost in maintenance, by Paul Taykalo, #SE2017 49
  26. Layer things out enum AppApiError: Error { case userNotLoggedIn case

    serverFeelsBad case subscriptionEnded case unknown(NetworkError) // } Lost in maintenance, by Paul Taykalo, #SE2017 50
  27. 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
  28. 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
  29. Semantic meaning if itemsCount > 4 if user.rating > 200

    && user.userName.isNotEmpty if view.tag == 13 Lost in maintenance, by Paul Taykalo, #SE2017 54
  30. 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
  31. 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
  32. Decrease amount of possible states » Optionals » BFO (Object)

    » Exponential number of states » Mutability Lost in maintenance, by Paul Taykalo, #SE2017 58
  33. 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
  34. 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
  35. - 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
  36. I'm not paying you for bug fixes! — angry customer

    Lost in maintenance, by Paul Taykalo, #SE2017 66
  37. 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
  38. 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
  39. Why we are (not) writing tests in iOS apps by

    Paul Taykalo, Stanfy @TT_Kilew Lost in maintenance, by Paul Taykalo, #SE2017 71
  40. Bonus Building a Swift Quiz App with TDD and Modular

    Design https://goo.gl/cUzTkr Lost in maintenance, by Paul Taykalo, #SE2017 73