Mockito
Encyclopedia
Mockito is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 testing framework for Java released under the MIT License
MIT License
The MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...

. The framework allows the creation of Test Double
Test Double
In computer programming and computer science, especially in object-oriented programming, programmers and developers employ a technique called, "automated unit testing" to enhance the quality of the software. Frequently, the final release software consists of a complex set of objects or procedures...

 objects called, "Mock Objects
Mock object
In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the...

" in automated unit tests
Test automation
Test automation is the use of software to control the execution of tests, the comparison of actual outcomes to predicted outcomes, the setting up of test preconditions, and other test control and test reporting functions...

 for the purpose of Test-driven Development
Test-driven development
Test-driven development is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new...

 (TDD) or Behavior Driven Development
Behavior driven development
Behavior-driven development is an agile software development technique that encourages collaboration between developers, QA and non-technical or business participants in a software project...

 (BDD).

Distinguishing Features

Mockito distinguishes itself from other mocking frameworks by allowing developers to verify the behavior of the system under test
System under test
System under test refers to a system that is being tested for correct operation. The term is used mostly in software testing.A special case of a software system is an application which, when tested, is called an application under test....

 (SUT) without establishing expectations beforehand. One of the criticisms of Mock objects
Mock object
In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the...

 is that there is a tighter coupling of the test code to the SUT
System under test
System under test refers to a system that is being tested for correct operation. The term is used mostly in software testing.A special case of a software system is an application which, when tested, is called an application under test....

 object code. Since Mockito attempts to eliminate the expect-run-verify pattern by removing the specification of expectations, the coupling is reduced or minimized. The result of this distinguishing feature is simpler test code that should be easier to read and modify.

Origins

Szczepan Faber started the Mockito project after finding existing mocking frameworks too complex and difficult to work with. Szczepan began by expanding on the syntax and functionality of Easy Mock, but eventually rewriting most of Mockito. Szczepan's goal was to create a new framework that was easier to work with and provided better results. Early versions of Mockito project found use by the Guardian project in London in early 2008.

Usage

Mockito has a growing user-base as well as finding use in other open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 projects. In the Stack Overflow
Stack overflow
In software, a stack overflow occurs when too much memory is used on the call stack. The call stack contains a limited amount of memory, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture,...

 discussion on What's the best mock framework for Java?, Mockito is the highest recommended answer.

See Also

  • List of mock object frameworks
  • Behavior driven development
    Behavior driven development
    Behavior-driven development is an agile software development technique that encourages collaboration between developers, QA and non-technical or business participants in a software project...

  • Mock object
    Mock object
    In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the...

  • List of unit testing frameworks
  • Software testing
    Software testing
    Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test. Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software...

  • Unit testing
  • PowerMock
    PowerMock
    PowerMock is a Java based framework that allows you to unit test code normally regarded as untestable. It is an extension to other mocking frameworks like Mockito or EasyMock. These frameworks are not able to mock certain language features like static methods or constructors. PowerMock enables...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK