1 / 19

Test Driven Development

Test Driven Development . Writing better code. By Stuart Mackey. Who is this guy…. …and why should I listen?. What will we talk about?. What is Unit testing? What is TDD? What are the benefits? How do you unit test in Xcode? Testing frameworks. What is Unit testing?.

orsen
Download Presentation

Test Driven Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test Driven Development Writing better code By Stuart Mackey

  2. Who is this guy…

  3. …and why should I listen?

  4. What will we talk about? • What is Unit testing? • What is TDD? • What are the benefits? • How do you unit test in Xcode? • Testing frameworks.

  5. What is Unit testing? Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. - Wikipedia

  6. What is a unit test? • Simply a method with three parts • Create the object under test • Exercise the object • Make an assertion

  7. Examples – Unit Test • (void)testCreateInstanceWithType { Foo *foo= [[Foo alloc] init]; foo.type = @”bar”; STAssertEqualStrings (foo.type, @”bar”, @”Type not bar”); }

  8. Examples - Asserts • STAssertNotNULL • STAssertNULL • STAssertNotEquals • STAssertEquals • STAssertGreaterThan • STAssertLessThan • STAssertEqualStrings • STAssertNotEqualStrings

  9. Examples – Unit Test • (void)testBruteForce { Foo *foo= [[Foo alloc] init]; for (int i=0; i<100; i++) { [foo setValue:i]; if (i== 50) { STAssertEqualStrings (foo.type, @”Type 50”, @”Type 50 not set”); } else { STAssertEqualStrings (foo.type, @”Other Type”, @”Other not set”); } } }

  10. Demo Unit testing and Xcode.

  11. What is TDD?

  12. TDD- Example Date entry and validation

  13. TDD – Think differently Before After OnClick { CalendarEntry *entry = [[CalendarEntry alloc] init]; entry.startDate = dateField.text; if ([entry isValidDate]) { self.errorMsg.text = entry.errorMsg; } } OnClick { if (![self dateValid:dateField.text]) { self.errorMsg.text = @”Invalid date”; } }

  14. Demo Thinking in objects

  15. What are the benefits? • Less ad-hoc testing • Fewer bugs • Cleaner code • Easier to maintain

  16. Testing Frameworks • All examples so far have used SimpleUnitTest • Others include OCUnit, GHUnit. • Varying levels of integration with Xcode.

  17. Useful links • http://en.wikipedia.org/wiki/Unit_testing • https://github.com/gabriel/gh-unit • http://mobileorchard.com/ocunit-integrated-unit-testing-in-xcode/ • http://cbess.blogspot.com/2010/05/simple-iphone-ipad-unit-test.html • http://www.mulle-kybernetik.com/software/OCMock/

  18. Contacts e: stuart@paperbagltd.com t: @stuartmackey w: http://www.paperbagltd.com

  19. Questions

More Related