DEV.co
Open-Source Testing · jonreid

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.

Source: GitHub — github.com/jonreid/OCMockito
991
GitHub stars
120
Forks
Objective-C
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryjonreid/OCMockito
Ownerjonreid
Primary languageObjective-C
LicenseMIT — OSI-approved
Stars991
Forks120
Open issues8
Latest releasev7.0.2 (2023-10-02)
Last updated2026-06-19
Sourcehttps://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.

Quickstart

Get the OCMockito source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/jonreid/OCMockito.gitcd OCMockito# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit testing legacy Objective-C codebases

Well-suited for existing iOS/macOS projects using Objective-C, where mock-based test isolation is needed without migrating to Swift or modern frameworks.

Reducing test fragility with 'nice' mocks

Ideal when tests should be resilient to unspecified method calls; mocks record interactions instead of throwing exceptions, reducing false failures.

Verification-heavy testing workflows

Supports record-then-verify patterns with flexible argument matchers and invocation counting, making behavior verification readable and maintainable.

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.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitPossible
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

OCMockito FAQ

Can I use OCMockito in Swift projects?
Not directly; OCMockito is Objective-C only. Swift projects require bridging headers or native Swift alternatives (e.g., Mockable, MockingKit).
Does OCMockito work with async methods?
Not clearly stated in provided data. Requires review of documentation or testing; Objective-C async patterns (completion blocks, GCD) may require custom handling.
How does OCMockito handle memory management?
Mocks are 'nice' (record interactions). Deallocation behavior is documented as problematic; avoid verifying dealloc. Otherwise uses standard Objective-C/ARC semantics.
Is OCMockito suitable for new projects?
Only if maintaining or extending Objective-C codebases. New iOS development should use Swift and native testing frameworks.

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.