SlideShare a Scribd company logo
BDD for iOS with Kiwi
     Oleksandr Gnatyshyn
Why BDD? Why Kiwi?

Kiwi is BDD library for iOS, «RSpec» like, easy to
                 setup and use.



      Kiwi               Kiwi built on top of OCUnit
                         and tightly integrated with
                         Xcode!
     OCUnit
Why BDD? Why Kiwi?
TDD - OCUnit :                                    BDD - Kiwi :
@implementation testTests
                                                  describe(@"Team", ^{
                                                      context(@"when newly created", ^{
- (void)testThatTeamShouldHaveName
                                                          it(@"should have a name", ^{
{
                                                              id team = [Team team];
    id team = [Team team];
                                                                    [[team.name should] equal:@"Black Hawks"];
    STAssertEqualObjects(team.name, @"Black
                                                              });
Hawks", @"Team shuld have a name");
                                                        });
                                                  });
}




1. Design                                         1. Nice structure
                                              +
2. Test Logic                                     2. Better Assertions
Kiwi installation


 •   Old School way -
     https://github.com/allending/Kiwi/wiki/Guide:-Up-and-Running-with-Kiwi




 •   Easy way - CocoaPods!!
//Podfile
platform :ios
  target :KiwiUnitTest, :exclusive => true do
      pod 'Kiwi'
  end
Basic usage
                                                                • SPEC_BEGIN(ClassName) and SPEC_END -
SPEC_BEGIN(SpecName)
                                                                macros that expand to begin and end a KWSpec class
describe(@"ClassName", ^{                                       and group declaration.

      context(@"a state the component is in", ^{
          __block id variable = nil;

            beforeAll(^{ // Occurs once
            });

            afterAll(^{ // Occurs once
            });

            beforeEach(^{ // Occurs before each enclosed "it"
                variable = [MyClass instance];
            });

            afterEach(^{ // Occurs after each enclosed "it"
            });

            it(@"should do something", ^{
                [[variable should] meetSomeExpectation];
            });

            context(@"inner context", ^{
                xit(@"does another thing", ^{
                });

                 pending(@"something unimplemented", ^{
                 });
            })
      });
});

SPEC_END
Basic usage
                                                                • SPEC_BEGIN(ClassName) and SPEC_END -
SPEC_BEGIN(SpecName)
                                                                macros that expand to begin and end a KWSpec class
describe(@"ClassName", ^{                                       and group declaration.

      context(@"a state the component is in", ^{                • describe(aString, aBlock) - starts a context that can
          __block id variable = nil;                            contain tests and nested contexts.
            beforeAll(^{ // Occurs once
            });                                                 • context(aString, aBlock) - synonym for describe.
            afterAll(^{ // Occurs once
            });

            beforeEach(^{ // Occurs before each enclosed "it"
                variable = [MyClass instance];
            });

            afterEach(^{ // Occurs after each enclosed "it"
            });

            it(@"should do something", ^{
                [[variable should] meetSomeExpectation];
            });

            context(@"inner context", ^{
                xit(@"does another thing", ^{
                });

                 pending(@"something unimplemented", ^{
                 });
            })
      });
});

SPEC_END
Basic usage
                                                                • SPEC_BEGIN(ClassName) and SPEC_END -
SPEC_BEGIN(SpecName)
                                                                macros that expand to begin and end a KWSpec class
describe(@"ClassName", ^{                                       and group declaration.

      context(@"a state the component is in", ^{                • describe(aString, aBlock) - starts a context that can
          __block id variable = nil;                            contain tests and nested contexts.
            beforeAll(^{ // Occurs once
            });                                                 • context(aString, aBlock) - synonym for describe.
            afterAll(^{ // Occurs once
            });                                                 • beforeAll(aBlock), afterAll(aBlock) - run once
            beforeEach(^{ // Occurs before each enclosed "it"
                                                                before and after all the inner contexts and it blocks of
                variable = [MyClass instance];                  the context it is in.
            });

            afterEach(^{ // Occurs after each enclosed "it"     • beforeEach(aBlock), afterEach(aBlock) - run before
            });                                                 and after every it block in all enclosed contexts.
            it(@"should do something", ^{
                [[variable should] meetSomeExpectation];        • it(aString, aBlock) - This is where actual actual
            });
                                                                expectations on objects should go
            context(@"inner context", ^{
                xit(@"does another thing", ^{
                });

                 pending(@"something unimplemented", ^{
                 });
            })
      });
});

SPEC_END
Basic usage
                                                                • SPEC_BEGIN(ClassName) and SPEC_END -
SPEC_BEGIN(SpecName)
                                                                macros that expand to begin and end a KWSpec class
describe(@"ClassName", ^{                                       and group declaration.

      context(@"a state the component is in", ^{                • describe(aString, aBlock) - starts a context that can
          __block id variable = nil;                            contain tests and nested contexts.
            beforeAll(^{ // Occurs once
            });                                                 • context(aString, aBlock) - synonym for describe.
            afterAll(^{ // Occurs once
            });                                                 • beforeAll(aBlock), afterAll(aBlock) - run once
            beforeEach(^{ // Occurs before each enclosed "it"
                                                                before and after all the inner contexts and it blocks of
                variable = [MyClass instance];                  the context it is in.
            });

            afterEach(^{ // Occurs after each enclosed "it"     • beforeEach(aBlock), afterEach(aBlock) - run before
            });                                                 and after every it block in all enclosed contexts.
            it(@"should do something", ^{
                [[variable should] meetSomeExpectation];        • it(aString, aBlock) - This is where actual actual
            });
                                                                expectations on objects should go
            context(@"inner context", ^{
                xit(@"does another thing", ^{
                });
                                                                • pending(aString, aBlock), xit(aString, aBlock) -
                                                                doesn't do anything other than log a pending message
                 pending(@"something unimplemented", ^{         to the output when run.
                 });
            })
      });
});

SPEC_END
DEMO
Thanks!

•   Kiwi repo - https://github.com/allending/Kiwi

•   NSScreencast(episode about kiwi) - http://nsscreencast.com/
    episodes/4-automated-testing-with-kiwi


•   Test Driving iOS Development with Kiwi by Daniel H
    Steinberg - iBooks Store Link

More Related Content

PDF
Spockを使おう!
PDF
Refactoring In Tdd The Missing Part
PPTX
Coding using jscript test complete
PDF
G*におけるソフトウェアテスト・シーズンIII
PDF
Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
PPTX
PPTX
Java and XML Schema
PDF
Candidacy
Spockを使おう!
Refactoring In Tdd The Missing Part
Coding using jscript test complete
G*におけるソフトウェアテスト・シーズンIII
Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Java and XML Schema
Candidacy

What's hot (9)

PPTX
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
PDF
Java Search Engine Framework
ODP
Buenos Aires Drools Expert Presentation
PDF
ERRest and Dojo
PPTX
Pragmatic unittestingwithj unit
PDF
A clean(er) architecture
PPTX
Java 7 + 8 new features
PDF
JRuby hacking guide
PDF
4 gouping object
TKPJava - Teaching Kids Programming - Core Java Langauge Concepts
Java Search Engine Framework
Buenos Aires Drools Expert Presentation
ERRest and Dojo
Pragmatic unittestingwithj unit
A clean(er) architecture
Java 7 + 8 new features
JRuby hacking guide
4 gouping object
Ad

Similar to Bdd for ios with kiwi (20)

PDF
Spock: A Highly Logical Way To Test
ODP
AST Transformations
ODP
Groovy Ast Transformations (greach)
PDF
Workshop Scala
KEY
Introducing CakeEntity
PDF
Stepping Up : A Brief Intro to Scala
PDF
Java Concurrency Gotchas
ODP
Groovy Testing
ODP
Ast transformations
PPT
比XML更好用的Java Annotation
PDF
Ts archiving
PDF
Introduction to Scala : Clueda
PDF
New Features Of JDK 7
PDF
iOS Behavior-Driven Development
PDF
Jasmine BDD for Javascript
PDF
JS OO and Closures
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
PPTX
Akka Actor presentation
PPT
Class loader basic
PPT
Scala uma poderosa linguagem para a jvm
Spock: A Highly Logical Way To Test
AST Transformations
Groovy Ast Transformations (greach)
Workshop Scala
Introducing CakeEntity
Stepping Up : A Brief Intro to Scala
Java Concurrency Gotchas
Groovy Testing
Ast transformations
比XML更好用的Java Annotation
Ts archiving
Introduction to Scala : Clueda
New Features Of JDK 7
iOS Behavior-Driven Development
Jasmine BDD for Javascript
JS OO and Closures
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Akka Actor presentation
Class loader basic
Scala uma poderosa linguagem para a jvm
Ad

Bdd for ios with kiwi

  • 1. BDD for iOS with Kiwi Oleksandr Gnatyshyn
  • 2. Why BDD? Why Kiwi? Kiwi is BDD library for iOS, «RSpec» like, easy to setup and use. Kiwi Kiwi built on top of OCUnit and tightly integrated with Xcode! OCUnit
  • 3. Why BDD? Why Kiwi? TDD - OCUnit : BDD - Kiwi : @implementation testTests describe(@"Team", ^{ context(@"when newly created", ^{ - (void)testThatTeamShouldHaveName it(@"should have a name", ^{ { id team = [Team team]; id team = [Team team]; [[team.name should] equal:@"Black Hawks"]; STAssertEqualObjects(team.name, @"Black }); Hawks", @"Team shuld have a name"); }); }); } 1. Design 1. Nice structure + 2. Test Logic 2. Better Assertions
  • 4. Kiwi installation • Old School way - https://github.com/allending/Kiwi/wiki/Guide:-Up-and-Running-with-Kiwi • Easy way - CocoaPods!! //Podfile platform :ios target :KiwiUnitTest, :exclusive => true do pod 'Kiwi' end
  • 5. Basic usage • SPEC_BEGIN(ClassName) and SPEC_END - SPEC_BEGIN(SpecName) macros that expand to begin and end a KWSpec class describe(@"ClassName", ^{ and group declaration. context(@"a state the component is in", ^{ __block id variable = nil; beforeAll(^{ // Occurs once }); afterAll(^{ // Occurs once }); beforeEach(^{ // Occurs before each enclosed "it" variable = [MyClass instance]; }); afterEach(^{ // Occurs after each enclosed "it" }); it(@"should do something", ^{ [[variable should] meetSomeExpectation]; }); context(@"inner context", ^{ xit(@"does another thing", ^{ }); pending(@"something unimplemented", ^{ }); }) }); }); SPEC_END
  • 6. Basic usage • SPEC_BEGIN(ClassName) and SPEC_END - SPEC_BEGIN(SpecName) macros that expand to begin and end a KWSpec class describe(@"ClassName", ^{ and group declaration. context(@"a state the component is in", ^{ • describe(aString, aBlock) - starts a context that can __block id variable = nil; contain tests and nested contexts. beforeAll(^{ // Occurs once }); • context(aString, aBlock) - synonym for describe. afterAll(^{ // Occurs once }); beforeEach(^{ // Occurs before each enclosed "it" variable = [MyClass instance]; }); afterEach(^{ // Occurs after each enclosed "it" }); it(@"should do something", ^{ [[variable should] meetSomeExpectation]; }); context(@"inner context", ^{ xit(@"does another thing", ^{ }); pending(@"something unimplemented", ^{ }); }) }); }); SPEC_END
  • 7. Basic usage • SPEC_BEGIN(ClassName) and SPEC_END - SPEC_BEGIN(SpecName) macros that expand to begin and end a KWSpec class describe(@"ClassName", ^{ and group declaration. context(@"a state the component is in", ^{ • describe(aString, aBlock) - starts a context that can __block id variable = nil; contain tests and nested contexts. beforeAll(^{ // Occurs once }); • context(aString, aBlock) - synonym for describe. afterAll(^{ // Occurs once }); • beforeAll(aBlock), afterAll(aBlock) - run once beforeEach(^{ // Occurs before each enclosed "it" before and after all the inner contexts and it blocks of variable = [MyClass instance]; the context it is in. }); afterEach(^{ // Occurs after each enclosed "it" • beforeEach(aBlock), afterEach(aBlock) - run before }); and after every it block in all enclosed contexts. it(@"should do something", ^{ [[variable should] meetSomeExpectation]; • it(aString, aBlock) - This is where actual actual }); expectations on objects should go context(@"inner context", ^{ xit(@"does another thing", ^{ }); pending(@"something unimplemented", ^{ }); }) }); }); SPEC_END
  • 8. Basic usage • SPEC_BEGIN(ClassName) and SPEC_END - SPEC_BEGIN(SpecName) macros that expand to begin and end a KWSpec class describe(@"ClassName", ^{ and group declaration. context(@"a state the component is in", ^{ • describe(aString, aBlock) - starts a context that can __block id variable = nil; contain tests and nested contexts. beforeAll(^{ // Occurs once }); • context(aString, aBlock) - synonym for describe. afterAll(^{ // Occurs once }); • beforeAll(aBlock), afterAll(aBlock) - run once beforeEach(^{ // Occurs before each enclosed "it" before and after all the inner contexts and it blocks of variable = [MyClass instance]; the context it is in. }); afterEach(^{ // Occurs after each enclosed "it" • beforeEach(aBlock), afterEach(aBlock) - run before }); and after every it block in all enclosed contexts. it(@"should do something", ^{ [[variable should] meetSomeExpectation]; • it(aString, aBlock) - This is where actual actual }); expectations on objects should go context(@"inner context", ^{ xit(@"does another thing", ^{ }); • pending(aString, aBlock), xit(aString, aBlock) - doesn't do anything other than log a pending message pending(@"something unimplemented", ^{ to the output when run. }); }) }); }); SPEC_END
  • 10. Thanks! • Kiwi repo - https://github.com/allending/Kiwi • NSScreencast(episode about kiwi) - http://nsscreencast.com/ episodes/4-automated-testing-with-kiwi • Test Driving iOS Development with Kiwi by Daniel H Steinberg - iBooks Store Link