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

Testing your Swift Code

Testing your Swift Code

Swift has experienced fantastic adoption over the past few years as developers transition away from Objective-C. Unfortunately, some of the tried and true Objective-C testing strategies don’t easily apply to Swift. In this talk we’ll take a deep dive into ways to test your Swift code. We’ll cover unit tests, UI tests, and introduce some helpful testing libraries. We’ll also talk about how you can take your tests to the next level by setting up a continuous integration and automatic deployment workflow.

Atomic Object

January 13, 2017
Tweet

More Decks by Atomic Object

Other Decks in Technology

Transcript

  1. ABOUT ME AT O M I C O B J

    E C T M AT T N E D R I C H @ M AT T N E D R I C H M AT T. N E D R I C H @ AT O M I C O B J E C T. C O M
  2. GOAL Introduce basic testing approaches in Swift Unit Tests UI

    Tests Discuss some useful libraries Continuous Integration & Automatic Deployment
  3. WHATS THE DEAL WITH SWIFT Limited reflection support Required by

    most mocking approaches Different runtime rules Can still write lots of great tests though
  4. H T T P : / / B L O

    G . P R A G M AT I C E N G I N E E R . C O M / S W I F T - T H E - O N LY - M O D E R N - L A N G U A G E - W I T H - N O - M O C K I N G - F R A M E W O R K /
  5. SWIFT TEST MOCKING Traditional mocking support does not exist Can

    create sub classes and override functions Must loosely couple things and rely on protocols for everything This can be great It can also lead to a large amount of unnecessary abstraction
  6. MOCKING LIBRARIES Some libraries do exist Usually create types ahead

    of time in batch Anyone have experience with them?
  7. UI TESTING Allow tests to perform UI interactions and assert

    behavior Similar to KIF tests Can work nicely as end-to-end or integration tests
  8. +

  9. CIRCLE CI IS NOW WORKING Your project will be built

    and tests will be run every time someone pushes to master Everyone subscribed to the Github repository will receive email notifications
  10. GOAL Every time a change is pushed to master Build

    project Run tests If tests pass, push build to TestFlight or HockeyApp, etc. Release build to test users with the press of a button
  11. STEP 2: CREATE CERTIFICATES fastlane cert --output_path certificates This will

    create three files something.cer something.certSigningRequest something.p12
  12. STEP 3: CREATE PROVISIONING PROFILE fastlane sigh This will create

    something like AppStore_com.mattnedrich.codemash-testing-demo.mobileprovision