Skip to content

Instantly share code, notes, and snippets.

@martin-nearsoft
Last active April 14, 2024 04:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin-nearsoft/c50ab78bc86f5f08f6b9 to your computer and use it in GitHub Desktop.
Save martin-nearsoft/c50ab78bc86f5f08f6b9 to your computer and use it in GitHub Desktop.
Objective-C Unit Testing - Specs
#define EXP_SHORTHAND
#import <Specta/Specta.h> // A light-weight TDD / BDD framework for Objective-C & Cocoa.
#import <Expecta/Expecta.h> // A Matcher Framework for Objective-C/Cocoa
#import <OCMock/OCMock.h> // An Objective-C implementation of mock objects
#import <OCMock/NSInvocation+OCMAdditions.h>
// 'beforeEach' and 'afterEach' are also aliased as 'before' and 'after' respectively.
// 'describe' is also aliased as 'context'.
// 'it' is also aliased as 'example' and 'specify'.
// Use 'pending' or prepend 'x' to 'describe' and 'it' to mark tests or groups as pending.
// Prepend 'f' to your 'describe' and 'it' to set focus on test or groups. (all unfocused specs are skipped)
SpecBegin(Thing)
describe(@"Thing", ^{
beforeAll(^{
// This is run once and only once before all of the tests
// in this group and before any beforeEach/before blocks.
});
before(^{
// This is run before each test in this group
});
it(@"should do stuff", ^{
// This is a test block. Place your assertions here.
});
it(@"should do some stuff asynchronously", ^AsyncBlock {
// Async test blocks need to invoke done() callback.
done();
});
describe(@"Nested test", ^{
// beforeAll ...
// before ...
it(@"should do even more stuff", ^{
// ...
});
// after ...
// afterAll ...
});
after(^{
// This is run after each test in this group.
});
afterAll(^{
// This is run once and only once after all of the tests
// in this group and after any afterEach/after blocks.
});
});
SpecEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment