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

[self shouldTest:@"iOS"]

[self shouldTest:@"iOS"]

From Codemash 2014!

7c2a83b93fe0e5f2ed4c95c59367259c?s=128

Amber Conville

January 09, 2014
Tweet

More Decks by Amber Conville

Other Decks in Programming

Transcript

  1. [self shouldTest:@”iOS”];

  2. what’s legacy code?

  3. why is it hard to unit test?

  4. why add unit tests you know why, but just in

    case…
  5. –Michael Feathers “Code without tests is bad code. It doesn’t

    matter how well written it is; it doesn’t matter how pretty or object-oriented or well- encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.”
  6. don’t • do it all at once, all the way,

    100% • do it just to do it • not cheat to make progress
  7. why kiwi? describe(@“Your Face”, ^{
 
 it(@“your face is amazing”,

    ^{
 Face *yourFace = [[Face alloc] init];
 [yourFace should] equal:@“amazing”];
 };
 
 context(@“You are happy”, ^{
 
 it(@“is smiling”, ^{
 Face *yourFace = [[Face alloc] init];
 [yourFace setMood:@“Happy”];
 [yourFace.expression should] equal:@“smiling”];
 });
 });
 };
  8. helpful kiwi anatomy describe
 context
 it
 beforeEach
 nullMock
 should receive:


    theValue()
 stub:
 stub:andReturn:
 stub:withBlock:
 captureArgument:atIndex:
  9. the set up

  10. this is taking forever do small changes, if you realize

    you've been doing it for a long time, revert and start with a smaller chunk
  11. i have no idea what it is doing characterization tests

    like whut.
 
 to the contrived example!
  12. this method is huge extract method where logical to test

    that, with an eye towards future collaborator
  13. ui views crash tests stub alloc/init for views

  14. it depends on everything isolate collaborators. objective-c makes this so

    easy, man! so easy!
  15. how do i mock an ivar turning ivars into properties

  16. privates everywhere expose em for tests only

  17. found block i cant even stub:withBlock: captureArgument:

  18. asynchronous…ness shouldEventually:
 or do that other thing we just did

  19. great, i cheated a lot, f u once you have

    a good suite of tests, you can stop cheating! extract your collaborators out with their tests. SRP, dawg!
  20. wait, what about greenfield? easy sauce. same tips, less barriers.

    go to town.
  21. None