10

Click here to load reader

Bdd for ios with kiwi

  • Upload
    gnat

  • View
    1.777

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Bdd for ios with kiwi

BDD for iOS with KiwiOleksandr Gnatyshyn

Page 2: Bdd for ios with kiwi

Why BDD? Why Kiwi?

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

OCUnit

KiwiKiwi built on top of OCUnit and tightly integrated with Xcode!

Page 3: Bdd for ios with kiwi

Why BDD? Why Kiwi?

TDD - OCUnit : BDD - Kiwi :

describe(@"Team", ^{ context(@"when newly created", ^{ it(@"should have a name", ^{ id team = [Team team];

[[team.name should] equal:@"Black Hawks"]; }); });});

@implementation testTests

- (void)testThatTeamShouldHaveName{ id team = [Team team]; STAssertEqualObjects(team.name, @"Black Hawks", @"Team shuld have a name"); }

1. Design2. Test Logic

+ 1. Nice structure2. Better Assertions

Page 4: Bdd for ios with kiwi

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

Page 5: Bdd for ios with kiwi

Basic usageSPEC_BEGIN(SpecName)

describe(@"ClassName", ^{

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

• SPEC_BEGIN(ClassName) and SPEC_END - macros that expand to begin and end a KWSpec class and group declaration.

Page 6: Bdd for ios with kiwi

Basic usageSPEC_BEGIN(SpecName)

describe(@"ClassName", ^{

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

• SPEC_BEGIN(ClassName) and SPEC_END - macros that expand to begin and end a KWSpec class and group declaration.

• describe(aString, aBlock) - starts a context that can contain tests and nested contexts.

• context(aString, aBlock) - synonym for describe.

Page 7: Bdd for ios with kiwi

Basic usageSPEC_BEGIN(SpecName)

describe(@"ClassName", ^{

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

• SPEC_BEGIN(ClassName) and SPEC_END - macros that expand to begin and end a KWSpec class and group declaration.

• describe(aString, aBlock) - starts a context that can contain tests and nested contexts.

• context(aString, aBlock) - synonym for describe.

• beforeAll(aBlock), afterAll(aBlock) - run once before and after all the inner contexts and it blocks of the context it is in.

• beforeEach(aBlock), afterEach(aBlock) - run before and after every it block in all enclosed contexts.

• it(aString, aBlock) - This is where actual actual expectations on objects should go

Page 8: Bdd for ios with kiwi

Basic usageSPEC_BEGIN(SpecName)

describe(@"ClassName", ^{

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

• SPEC_BEGIN(ClassName) and SPEC_END - macros that expand to begin and end a KWSpec class and group declaration.

• describe(aString, aBlock) - starts a context that can contain tests and nested contexts.

• context(aString, aBlock) - synonym for describe.

• beforeAll(aBlock), afterAll(aBlock) - run once before and after all the inner contexts and it blocks of the context it is in.

• beforeEach(aBlock), afterEach(aBlock) - run before and after every it block in all enclosed contexts.

• it(aString, aBlock) - This is where actual actual expectations on objects should go

• pending(aString, aBlock), xit(aString, aBlock) - doesn't do anything other than log a pending message to the output when run.

Page 9: Bdd for ios with kiwi

DEMO