Skip to content
/ records Public

Just a little showcase app to compare writing tests with OCUnit vs. Specta

Notifications You must be signed in to change notification settings

sens3/records

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Records

A little showcase app to compare writing tests/specs with OCUnit (TDD) vs. Specta (BDD).

TL;DR

Compare these two files:

and decide for yourself which one you like better.

Setup

Please run pod install before building the app.

Where to find them

  • Folder RecordsTests holds the OCUnit tests.
  • Folder RecordsSpecs holds the Specta specs.

How to run them seperately (if you want to)

  • Scheme RecordsTests will only run the OCUnit tests.
  • Scheme RecordsSpecs will only run the Specta specs.

More Info

Specta

Specta is a BDD Framework very similar to Cedar (by Pivotal) or Kiwi. All of these were heavily influenced by RSpec, a Ruby BDD framework.

If you leave the philosophical differences between TDD and BDD aside, the one huge benefit of using something like Specta is that it allows you to easily organize and group your tests (or "specs").

So, instead of having to keep all information in just the test method name

- (void)test_RecordListVC_viewDidLoad_setsTheTableViewDelegate

you can group your tests like

describe(@"RecordListViewController", ^{
    
    before(^{
    	// stuff I need for all tests
    });
    
    describe(@"viewDidLoad", ^{
    	before(^{
    		// stuff I only need for this sub group of tests
    	});
    	
    	it(@"sets the table view delegate", ^{
        	// assert things here
    	});
    });
});    	

Which makes it much easier to navigate through your specs and identify what is being tested where.

Also, as you can see in the example above, you can have a before method (similar to setup in OCUnit) for each describe block (meaning for each group of tests).

This allows you do exactly the setup you need for an individual group of tests.

In OCUnit you could have either just put everything in the setup method (not always possible if you have competing values for a variable) or create a seperate TestCase for a group of tests.

Github: https://github.com/petejkim/specta

Expecta

Expecta is a Matcher framework. If you look at the specs, Expecta is what allows you to write things like

expect(@foo).to.equal(@"bar")

instead of

STAssertEqualObjects(@foo, @"bar", nil);

There are alternatives, but this is written by the same guy who wrote Specta (who'd have guessed, right?) so I just rolled with it.

Github: https://github.com/petejkim/expecta

OCMockito

A Mocking framework alternative to OCMock.

Pros: nicer syntax

Cons: no partial mocks

Github: https://github.com/jonreid/OCMockito

KIF

I also added a few functional tests using KIF.

You can either run it from within XCode by using the RecordsIntegrationTests scheme.

Or you can use the runkif.sh script, it depends on ios-sim which can be installed via homebrew:

brew install ios-sim

About

Just a little showcase app to compare writing tests with OCUnit vs. Specta

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published