OCMockito
OCMockito is an Objective-C mocking framework based on Mockito, enabling creation, verification, and stubbing of mock objects in unit tests. It prioritizes readable, non-fragile tests by using a record-then-verify pattern instead of expect-run-verify.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | jonreid/OCMockito |
| Owner | jonreid |
| Primary language | Objective-C |
| License | MIT — OSI-approved |
| Stars | 991 |
| Forks | 120 |
| Open issues | 8 |
| Latest release | v7.0.2 (2023-10-02) |
| Last updated | 2026-06-19 |
| Source | https://github.com/jonreid/OCMockito |
What OCMockito is
OCMockito provides a Mockito-style API for mocking Objective-C classes, protocols, and objects. Key features include automatic call recording ('nice' mocks), argument matchers via OCHamcrest integration, support for struct returns, KVO-compatible property stubbing, and argument capturing for assertions.
Get the OCMockito source
Clone the repository and explore it locally.
git clone https://github.com/jonreid/OCMockito.gitcd OCMockito# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires OCHamcrest as a dependency for argument matchers; ensure compatibility with your project's testing stack.
- Mocking `dealloc` is problematic (documented limitation); design tests to avoid verifying deallocation behavior.
- Struct return stubbing requires `@encode()` type introspection; adds syntactic overhead for complex return types.
- Property stubbing (`stubProperty`) only affects the mock, not KVO observers; verify KVO behavior separately if needed.
- Works with Xcode's XCTest; integrates via CocoaPods, Carthage, or Swift Package Manager.
When to avoid it — and what to weigh
- Migrating to Swift is planned — OCMockito is Objective-C only; Swift projects should use native testing libraries (XCTest, MockingKit) or Swift-compatible alternatives.
- High performance, security-critical testing is required — Unknown performance characteristics; not evaluated for security-sensitive or performance-critical test suites. Requires profiling.
- Greenfield projects or modern iOS development — Objective-C is legacy; new iOS projects typically use Swift with native mocking or frameworks like Mockable.
- Async/concurrent code testing — Not clearly stated whether OCMockito handles async/await or complex concurrency patterns; requires verification for such use cases.
License & commercial use
Licensed under MIT (permissive Open Source Initiative license). Commercial use, modification, and distribution are allowed with retention of copyright and license notice.
MIT is a permissive OSI-approved license explicitly allowing commercial use without restrictions beyond copyright attribution. No special commercial licensing or vendor restrictions noted in provided data.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Possible |
| Assessment confidence | High |
No documented security vulnerabilities, exploit vectors, or sensitive data handling concerns provided. Mocking framework operates in test context only; not suitable for production code. Requires runtime reflection (Objective-C runtime introspection); ensure test environment is isolated.
Alternatives to consider
OCMock
Older, more permissive Objective-C mocking framework; uses expect-run-verify pattern (less readable). Still active but larger learning curve.
Nimble + Quick
Swift-native BDD testing framework; recommended for Swift projects. Not Mockito-style but idiomatic to modern iOS development.
MockingKit (Swift)
Modern Swift mocking library with record-then-verify semantics; suitable for projects migrating from Objective-C or greenfield Swift apps.
Build on OCMockito with DEV.co software developers
OCMockito offers readable, Mockito-style mocking for Objective-C codebases. Assess compatibility with your XCTest setup, OCHamcrest integration, and long-term maintenance needs before adoption.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
OCMockito FAQ
Can I use OCMockito in Swift projects?
Does OCMockito work with async methods?
How does OCMockito handle memory management?
Is OCMockito suitable for new projects?
Work with a software development agency
From first prototype to production, DEV.co delivers software development services around tools like OCMockito. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.
Evaluate OCMockito for Your Objective-C Test Suite
OCMockito offers readable, Mockito-style mocking for Objective-C codebases. Assess compatibility with your XCTest setup, OCHamcrest integration, and long-term maintenance needs before adoption.