All Projects → shepting → kiwi-mac-demo

shepting / kiwi-mac-demo

Licence: other
A sample Mac OS X app using Kiwi for unit-testing.

Programming Languages

XML
50 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Using Kiwi for Mac OS X Development

Kiwi is an excellent unit-testing framwork for iOS and Mac. Unfortunately, it was a bit of a hassle to set up for the Mac and so I created this demo project with instructions. It uses CocoaPods to install and then changes one build setting.

The setup instructions are also on the official Kiwi wiki: https://github.com/allending/Kiwi/wiki/Up-and-Running-with-Kiwi-for-Mac

Short Version

  1. Make a new project
  2. Create/Add Kiwi to existing Podfile
  3. Run (in the terminal): pod install
  4. Change test file to Kiwi Spec, run tests (cmd + U)

Long Version

1. Create a New Project

First, create a new project in Xcode. In the sidebar on the left choose "Application" under the "Mac OS X" section.

There will be an action sheet drop-down with options.

2. Add Podfile

Create a file named Podfile. Update the target names to match those in your app (MacApp and MacAppTests will become something like RidgeRacer and RidgeRacerTests). Add whatever other pods you'd like to either target. If you don't yet have CocoaPods, follow the directions here: https://github.com/CocoaPods/CocoaPods

# Test podfile for Mac

platform :osx, '10.8'

target 'MacApp', :exclusive => true do
  pod 'AFNetworking'
end

target 'MacAppTests', :exclusive => true do
    pod 'Kiwi/XCTest'
end

In the terminal run:

$> pod install

3. Remove Default Tests, Add Spec File

There will be two files (MacAppTests.h and MacAppTests.m) in the tests group (MacAppTests). You can delete these.

Add a new spec file (SHAppDelegateSpec.m) to this group.

#import "SJHAppDelegate.h"
#import "Kiwi.h"

SPEC_BEGIN(SJHAppDelegateSpec)

describe(@"SHAppDelegateSpec", ^{
    __block SJHAppDelegate *dm;
    
    beforeEach(^{
        dm = [[SJHAppDelegate alloc] init];
    });
    
    context(@"application:DidFinishLaunching:", ^{
        
        it(@"should call call", ^{
            [[dm should] receive:@selector(firstCall)];
            
            [dm applicationDidFinishLaunching:nil];
        });
        
        it(@"should call otherCall", ^{
            [[dm should] receive:@selector(otherCall)];
            
            [dm applicationDidFinishLaunching:nil];
        });
    });
});

SPEC_END

5. Test (cmd + U)

Press CMD + U to run the tests. They should both fail. Update your app delegate file with two dummy methods and have applicationDidFinishLaunching: call them and the tests should pass. Done!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].