Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Isolation Framework and Mock Framework

What the difference between terms 'Isolation Framework' and 'Mocking Framework'?

like image 991
madcyree Avatar asked Jan 06 '13 14:01

madcyree


People also ask

What are mocking frameworks?

What is a mocking framework? Mocking frameworks are used to generate replacement objects like Stubs and Mocks. Mocking frameworks complement unit testing frameworks by isolating dependencies but are not substitutes for unit testing frameworks.

What is the name of a mocking framework?

Mockito is an open-source framework that allows us to easily create test doubles (mocks). Test Double is a generic term for any case where you replace a production object for testing purposes.

What is mock framework Java?

Mockito is a mocking framework, JAVA-based library that is used for effective unit testing of JAVA applications. Mockito is used to mock interfaces so that a dummy functionality can be added to a mock interface that can be used in unit testing.

What is isolation in testing?

Isolation testing is the process of breaking down the system into various modules so that defects can be spotted easily in isolation. It happens especially when the bug is difficult to locate and resolve by development team.


2 Answers

I feel the accepted answer is wrong, mock frameworks are isolation frameworks as well.

Section 5.1 from Roy Oshroves book "The Art of Unit Testing" says

An isolation framework is a set of programmable APIs that make creating mock and stub objects much easier. Isolation frameworks save the developer from the need to write repetitive code to test or simulate object interactions.

This definition may sound a bit bland, but it needs to be generic in order to include the various isolation frameworks out there. Isolation frameworks exist for most languages that have a unit-testing framework associated with them. For example, C++ has mockpp and other frameworks, and Java has jMock and EasyMock, among others. .NET has NMock, Moq, Typemock Isolator, and Rhino Mocks.

In a blog post by him he mentions that

isolation framework (mocking framework… but that is a horrible name for it. the word mock is overloaded already)

So they typically refer to the same thing. An isolation framework can be used to initiate mocks, but it also applies to other test doubles. An isolation framework would be a superset of which a mock framework is a part of.

A test double is an umbrella term for

  • test stubs
  • fake objects
  • test spies and
  • mock objects

The four types are from Lasse Koskela, book Effective Unit Testing. Martin Fowler and Gerard Meszaros list five types:

  • dummy objects
  • fake objects
  • stubs
  • spies and
  • mocks

but the distinction is the same.

like image 111
eis Avatar answered Oct 14 '22 10:10

eis


Quite often those two terms used interchangeably, but there is an important difference. In my opinion, there is a similar difference as between stubs and mocks. Stub i.e. Isolation Framework only provides predefined outputs, and thus isolates "test" from external system with complex internal state, slow response time, etc. Mock i.e. Mock Frameworks not only provides predefined outputs if needed, but also has pre-programmed with expectations which form a specification of the calls they are expected to receive. Thus mock tracks its usage and fails "test" if used inappropriately. But stub only provides predefined output.

You could found more at Mocks Aren't Stubs article by Martin Fowler

like image 33
Akim Avatar answered Oct 14 '22 11:10

Akim