My TDD ReBoot

An old gray hair learns to code - again.


My area of study these last few months has been Swift for iOS Apps. I've written lots of example code - but that only takes your learning so far (and it's not far enough!) - so I ventured beyond tutorials and wrote an App for some colleagues and published in the Apple Store. Now that required lots of learning that is not in the tutorials. See InspireMe! Cards - Real Advice for Agilists

https://www.inspiremecards.app

I wrote that App without any automated test. Decided that was NOT the way to go in the future. So I needed to dust off the old Java TDD skills and apply to Swift.

Xcode has wonderful integration for unit testing & even UI testing & performance testing.

A card flipping App doesn't have much business logic nor Obj model - but has lots of views in the SwiftUI world. So testing the View layer is the primary need. Trying to learn the UI testing layer inside of Xcode is very difficult... can't seem to find much documentation. All the examples of course WORK... but my attempts do not... so learning from "canned examples" is not fruitful.

I was invited to James Greening's TDD course and jumped at that opportunity - he's a rock star in the TDD community and I highly recommend his awesome TDD course. Even if you are NOT an embedded C/C++ programmer you will learn lots from James. And to get a glimpse at his work flow - well it is MIND-BLOWING. Do not think you know what TDD is until you've seen a master in action... to generalize; YOU are taking WAY to BIG of a STEP!

To solve this problem - I teamed up with the good folks at TDD.Academy and Lance Kind. He's mentoring me in TDD on Swift UI with iOS App dev on his Live Coding Stream TDD.Academy - shameless plug: https://www.twitch.tv/tddacademy/videos

Yet I've still got many many questions. And I've learned lots in the last several months. I now consider my self a TDD beninnger and perhaps competent in SwiftUI Testing... which means I can spend hours banging my head on a testing of a simple iOS app and fix it the next day - Competent.

So what have I learned: (maybe this is a good place for a list)

- Doing TDD is way easier with a mentor (programming pair) - I still forget to write the test first.

- Testing the Zero (NULL) case first

- Using the Empty-Class pattern

- Learning to craw - before I attempt to RUN.

- Tons of Swift & SwiftUI stuff

- SwiftUI toolbars don't play well with the testing ID accessibilityIdentifier() - so you can quit banging your head on this one - my head is flat.

- UI tests are NOT fast... 3 orders of magnitude slower than a unit test.

- You MUST speed this up... so you go get View Inspector and learn to unit test the View layer.

- Even View Inspector has problems with toolbars... so you go back to head banging...

- Apple has a big war chest of money - and then are not spending it on programmer documentation

- You need to know your View hierarchy - so in a test "print(app.debugDescription)" - is Your savior

- You could try the dev tool - Accessibility Inspector - but you will return to the print statement.

- You have to GROK the XCUI element query stuff... and no one will talk about it in the examples/tutorials

- You guessed it Apple doesn't understand it so they did not document XCUI Element Query...

- so something like app.buttons["my_button"].tap() might just poke your buttons