Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Mockito for Objective-C: creation, verification and stubbing of mock objects
| Date | Stars |
|---|---|
| 2026-07-24 | 991 |
| 2026-07-25 | 991 |
| 2026-07-28 | 991 |
| 2026-07-30 | 991 |
| 2026-08-06 | 991 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day

# OCMockito
[](https://github.com/jonreid/OCMockito/actions/workflows/build.yml)
[](https://coveralls.io/r/jonreid/OCMockito)
[](https://swiftpackageindex.com/jonreid/OCMockito)
[](https://github.com/Carthage/Carthage)
[](https://cocoapods.org/pods/OCMockito)
OCMockito is an Objective-C implementation of Mockito, supporting creation,
verification and stubbing of mock objects.
Key differences from other mocking frameworks:
* Mock objects are always "nice," recording their calls instead of throwing
exceptions about unspecified invocations. This makes tests less fragile.
* No expect-run-verify, making tests more readable. Mock objects record their
calls, then you verify the methods you want.
* Verification failures are reported as unit test failures, identifying specific
lines instead of throwing exceptions. This makes it easier to identify
failures.
<!-- toc -->
## Contents
* [Let's verify some behavior!](#lets-verify-some-behavior)
* [How about some stubbing?](#how-about-some-stubbing)
* [How do you mock a class object?](#how-do-you-mock-a-class-object)
* [How do you mock a protocol?](#how-do-you-mock-a-protocol)
* [How do you mock an object that also implements a protocol?](#how-do-you-mock-an-object-that-also-implements-a-protocol)
* [How do you stub methods that return primitives?](#how-do-you-stub-methods-that-return-primitives)
* [How do you stub methods that return structs?](#how-do-you-stub-methods-that-return-structs)
* [How do you stub a property so that KVO works?](#how-do-you-stub-a-property-so-that-kvo-works)
* [Argument matchers](#argument-matchers)
* [How do you specify matchers for non-object arguments?](#how-do-you-specify-matchers-for-non-object-arguments)
* [Verifying exact number of invocations / at least x / never](#verifying-exact-number-of-invocations--at-least-x--never)
* [Capturing arguments for further assertions](#capturing-arguments-for-further-assertions)
* [Stubbing consecutive calls](#stubbing-consecutive-calls)
* [Stubbing with blocks](#stubbing-with-blocks)
* [Problems with dealloc](#problems-with-dealloc)
* [How do you mock a singleton?](#how-do-you-mock-a-singleton)
* [How do I add OCMockito to my project?](#how-do-i-add-ocmockito-to-my-project)
* [Swift Package Manager](#swift-package-manager)
* [CocoaPods](#cocoapods)
* [Carthage](#carthage)
* [Prebuilt Framework](#prebuilt-framework)
* [Build Your Own](#build-your-own)
* [About the Author](#about-the-author)<!-- endToc -->
## Let's verify some behavior!
```obj-c
// mock creation
NSMutableArray *mockArray = mock([NSMutableArray class]);
// using mock object
[mockArray addObject:@"one"];
[mockArray removeAllObjects];
// verification
[verify(mockArray) addObject:@"one"];
[verify(mockArray) removeAllObjects];
```
Once created, the mock will remember all interactions. Then you can selectively
verify whatever interactions you are interested in.
(If Xcode complains about multiple methods with the same name, cast `verify`
to the mocked class.)
## How about some stubbing?
```obj-c
// mock creation
NSArray *mockArray = mock([NSArray class]);
// stubbing
[given([mockArray objectAtIndex:0]) willReturn:@"first"];
[given([mockArray objectAtIndex:1]) willThrow:[NSException exceptionWithName:@"name"
reaExcerpt of 15,372 characters
Read on GitHub1.1k
9
9
9
7
6
6
@actions
5
4
4
2
2
2
2
2
2
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:335533cb5edac045, topic:testing