Slide 1

Slide 1 text

(Unit) Testing iOS Apps Paweł Dudek

Slide 2

Slide 2 text

So a QA guys walks into your room…

Slide 3

Slide 3 text

That’s a lot of wasted time.

Slide 4

Slide 4 text

Could it be saved?

Slide 5

Slide 5 text

YES!!! If only we had a better test coverage...

Slide 6

Slide 6 text

One of the many reasons why you want to have tests. What are the others?

Slide 7

Slide 7 text

Reasons for testing • Saved time • Better codebase • Faster development cycles • Being “confident” about your code • More saved time

Slide 8

Slide 8 text

More saved time? What?

Slide 9

Slide 9 text

Common misconceptions

Slide 10

Slide 10 text

Common misconceptions • “It will take longer to write code” or “Time spent writing/refactoring tests is time lost” • “It will take more time to modify existing system”

Slide 11

Slide 11 text

Am I going to write poor software if I don’t do tests?

Slide 12

Slide 12 text

Are unit tests an invaluable tool for writing great software? Heck yes.  Am I going to produce a poor product if I can’t unit test? Hell no. Jonathan Rasmusson

Slide 13

Slide 13 text

Now that we know that writing tests is a good idea...

Slide 14

Slide 14 text

How can we do it?

Slide 15

Slide 15 text

• You will feel confused • You won’t know how to start • You will need help • Conclusion: it’s not easy to start

Slide 16

Slide 16 text

Tips • Never think of tests as tests • Think of a scenario, behavior, example • Grab a mature project from github with tests included • Find someone experienced and ask questions • Program in pairs!

Slide 17

Slide 17 text

Get on with it! How can we test?

Slide 18

Slide 18 text

Working effectively with legacy code Michael C. Feathers

Slide 19

Slide 19 text

TDD • Test Driven Development • Red, Green, Refactor • Write failing test first • Fix it • Refactor

Slide 20

Slide 20 text

BDD Behavior Driven Development

Slide 21

Slide 21 text

How does BDD differ from TDD?

Slide 22

Slide 22 text

BDD builds upon TDD by formalising the good habits of the best TDD practitioners. Matt Wynne, XP Evangelist

Slide 23

Slide 23 text

Good habits

Slide 24

Slide 24 text

Unit Tests

Slide 25

Slide 25 text

OCUnit

Slide 26

Slide 26 text

OCUnit Syntax • All test classes inherit from SenTestCase • All tests begin with test • Setup and teardown method • Everything else is ignored by testing framework • Means you can use as additional setup methods!

Slide 27

Slide 27 text

-(void)testFullName { Person *person = [Person person]; person.firstName = @"Mariusz"; person.secondName = @"Testowniczek"; NSString *fullName = [person fullName]; NSString *expectedName = @"Mariusz Testowniczek"; STAssertTrue([fullName isEqualToString:expectedName], @""); }

Slide 28

Slide 28 text

OCUnit vs XCTest

Slide 29

Slide 29 text

OCUnit vs XCTest

Slide 30

Slide 30 text

Behavior Tests

Slide 31

Slide 31 text

Kiwi and Cedar

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

SPEC_BEGIN(PersonSpec) ! describe(@"Person", ^{ __block Person *person; ! beforeEach(^{ person = [[Person alloc] init]; person.firstName = @"Mariusz"; person.lastName = @"Fixture Last Name"; }); ! describe(@"full name", ^{ ! __block NSString *fullName; ! beforeEach(^{ fullName = [person fullName]; }); ! it(@"should return the full name", ^{ expect(fullName).to(equal(@"Mariusz Testowniczek")); }); }); }); ! SPEC_END

Slide 34

Slide 34 text

iOS Testing Tips

Slide 35

Slide 35 text

Testing UI Layout

Slide 36

Slide 36 text

System Singletons

Slide 37

Slide 37 text

Common caveats

Slide 38

Slide 38 text

Example

Slide 39

Slide 39 text

More advanced topics

Slide 40

Slide 40 text

Summary

Slide 41

Slide 41 text

Summary • Testing is a great way to help developers • Better codebase, faster iterations • Invaluable for larger projects

Slide 42

Slide 42 text

Resources & Contact @eldudi github.com/paweldudek [email protected] Code Examples Contact