Open source .NET mocking framework for creating test doubles and isolating dependencies in unit tests.
Vendor
Hibernating Rhinos
Company Website
Rhino Mocks is an open source mocking framework for the .NET platform. It is designed to support unit testing by allowing developers to create mock objects that simulate the behavior of dependencies. The framework enables the isolation of components under test by replacing external dependencies such as services, repositories, or interfaces with controllable test doubles. Developers can define expected interactions, return values, exceptions, and method call constraints to validate system behavior. Rhino Mocks supports both record/replay and arrange/act/assert testing styles. It integrates with common .NET unit testing frameworks and is typically used in test projects alongside production code. The primary goal of Rhino Mocks is to facilitate automated testing by reducing coupling between components and making behavior verification explicit and reproducible.
Key Features
Mock Object Creation Generates mock implementations of interfaces and virtual members.
- Create dynamic mocks at runtime
- Mock interfaces and classes with virtual methods
- Substitute external dependencies
- Reduce reliance on concrete implementations
Expectation Definition Allows specification of expected interactions.
- Define expected method calls
- Set return values
- Configure exceptions
- Verify invocation counts
Verification Mechanisms Ensures that defined expectations are met.
- Automatic verification in replay mode
- Explicit verification methods
- Detection of unexpected calls
- Validation of interaction order (where applicable)
Multiple Testing Styles Supports different test structuring approaches.
- Record/Replay model
- Arrange/Act/Assert syntax
- Flexible API usage
- Compatible with behavior-driven approaches
Integration with .NET Test Frameworks Designed for use within .NET testing environments.
- Works with common unit testing frameworks
- Suitable for automated test pipelines
- Embedded in standard test projects
- No standalone runtime required
Benefits
Improved Test Isolation Separates the unit under test from external dependencies.
- Eliminates dependency on databases or services
- Enables deterministic tests
- Reduces environmental variability
Faster Test Execution Replaces heavy dependencies with lightweight mocks.
- Shorter feedback cycles
- Efficient automated test runs
- Supports continuous integration workflows
Clear Interaction Verification Makes behavioral expectations explicit.
- Confirms correct method usage
- Detects unintended side effects
- Improves confidence in refactoring
Better Maintainability Encourages loosely coupled design.
- Promotes interface-driven architecture
- Simplifies component replacement
- Supports modular system structure
Open Source Availability Provides access to implementation details.
- Inspectable source code
- Community usage and contributions
- Adaptable to project-specific needs