Skip to content

Instantly share code, notes, and snippets.

Last active May 18, 2021 08:43
Show Gist options
  • Save orkoden/201f811570582fab2b5b to your computer and use it in GitHub Desktop.
Save orkoden/201f811570582fab2b5b to your computer and use it in GitHub Desktop.
Notes from TDD iOS Notes

TDD Workshop Notes

Twitter hashtag #tddberlin

Mobile Central Europe Conference in Warsaw in Feb 2015



book Michael Feathers - Working With Legacy Code

Blog post



Introduction to tests and testing framework

Pawel Dudek @eldudi

Unit test life cycle

Arrange - set up

Act - do something

Assert - check result

What a unit test is not

Read book Michael Feathers - Working With Legacy Code

  • talks to database, filesystem, network
  • edit config files or environment

Property of a good unit test


Has to be FAST!


Write test first!

Gets you into the zone

Helps track work

Use your own API before someone else or the rest of the app

If it's hard to test, it's hard to use.

Reduce amount of QA and testing. You will still have bugs.


Work from the outside in

Use examples to clarify requirements



Define specifications

Describe and context block

beforeEach - Arrange and Act

it - Assert

afterEarch - destroy created objects and state from beforeEach

Separation into beforeEach and it

focusing tests





it(@"bla", PENDING)

Perfect setup

run tests automatically on each change of a file

xcpretty - simplify xcodebuild output to one . per test. builds faster

My questions

What does Specta do, that XCTest does not?

Red Green Factor

Aleksader Zubala @alekzubala

develop in short repeatable cycles

form hypothesis and check them

confidence to refactor

improve code quality


What will move the project forward?

  1. Write test (object and method might not exist). AppCode makes it easy to create missing files, methods
  2. Test Fails


Solution does not have to be the best one. Even hardcoding is ok.

Make test pass. Test the test.


Improve solution. Acutally implement.

DRY - don't repeat yourself


Red, Green, Refactor

What do you get

Baby steps

spend most time on refactoring

easy to identify what goes wrong

Common mistakes

move quickly through red, green phases

make cycles short

don't forget refactoring


Add correct index when opening swiping preview.

Types of Test

Return test, value test

When faking, mocking objects you might have to create categories. Only add those to the test target.

describe and context is used to structure the tests

describe -

context -

Interaction Test





Mock, Spy

Stub, Fake

How to work with legacy code effectively

Maciej Oczko @maciejoczko

Creating a new spec file

File, new - File (not new class) - ClassToTestSpec.m

Add to to test target

type cspec + tab to create starting test code


  • test if rightBarButtonItem changes correctly

Testing View related methods

View lifecycle methods (viewDidLoad etc.) are not called automatically. You have to call them yourself.

Be careful: calling -[UIViewcontroller view] will call loadView, viewDidLoad. But will not call viewWillAppear.


Find inflection point: narrow interface to a set of classes

example here: Singleton PollManager made testing difficult

  • break external dependencies with dependency injection (passing parameters e.g. initWith:)
  • break internal dependencies with extracting a small method

After that make changes.


extract validation logic to test textfiel validation. lines 116-138


cit is live template (code snippet) that expands. See Settings -> Live templates

alt+enter - create class, create missing methods etc.

alt+cmd+c - create constants from repeated strings

cmd+shift+t - switch from test to implementation class

alt+enter - dow what i need, like create new class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment