Glossary · Automation software engineering and architecture
Mock object
Also known as: Mock
German: Mock-Objekt
In software testing, a mock object is a test double that replaces a real dependency and checks that the code under test calls it in the expected way, for example with the right arguments and number of calls.
- Software engineering
In one sentence
A mock object is a test double that replaces a dependency and verifies that the code under test calls it as expected.
Example
A unit test of the valve control function block uses a mock of the output module to check that the close command is sent exactly once after the timeout.
How it applies
- Engineering: Mocks let a Unit test run without hardware, fieldbus or database. They work best when dependencies are injected through interfaces, see Dependency injection.
- Verification: A mock checks interactions, not the real behavior of the dependency. Tests with mocks must therefore be complemented by Hardware-in-the-loop tests or integration tests on real components.
- Documentation: Test specifications should state which dependencies are mocked, so reviewers and assessors can judge what a passed test actually demonstrates.
Mock vs. stub
Both are kinds of Test double. A stub only returns prepared answers so the test can run; a mock additionally verifies how it was called. Teams often use the word mock for both.