Mockito is an open source testing framework for Java released under the MIT License.[1][2] The framework allows the creation of test double objects (mock objects) in automated unit tests for the purpose of test-driven development (TDD) or behavior-driven development (BDD).
The framework's name and logo are a play on mojitos, a type of drink.
Features
Mockito allows developers to verify the behavior of the system under test (SUT) without establishing expectations beforehand.[3] One of the criticisms of mock objects is that there is a tight coupling of the test code to the system under test.[4] Mockito attempts to eliminate the expect-run-verify pattern[5] by removing the specification of expectations. Mockito also provides some annotations for reducing boilerplate code.[6]
Origins
Mockito began by expanding on the syntax and functionality of EasyMock.[7][8]
Example
Consider this decoupled Hello world program; we may unit test some of its parts, using mock objects for other parts.
The result of HelloApplication launching will be the following:
application: hello world
Unit test for HelloActable component may look like this:
It uses mock objects for the Greeter and Appendable interfaces, and implicitly assumes the next use case:
unitTest : hi world
Integration test code for testing HelloActable wired together with Greeter may look like the following:
It uses mock objects only in place of Appendable interfaces, uses the real implementations for other (HelloActable and Greeter) interfaces, and implicitly assumes the next use case:
integrationTest says welcome universe
As can be seen from the import statements of HelloActionUnitTest and HelloActionIntegrationTest classes, it is necessary to put some Mockito jars and JUnit jars in your class path to be able to compile and run the test classes.
See also
Behavior driven development
List of unit testing frameworks
Software testing
References
1. ^{{cite web |url= http://gojko.net/2009/10/23/mockito-in-six-easy-examples/ |title=Mockito in six easy examples |year=2009 | accessdate=2012-10-05 }} 2. ^{{cite web |url=https://stackoverflow.com/questions/22697/whats-the-best-mock-framework-for-java |title=What's the best mock framework for Java? |accessdate=2010-12-29 }} 3. ^{{cite web |url=https://code.google.com/p/mockito/wiki/FeaturesAndMotivations |title=Features and Motivations |accessdate=2010-12-29 }} 4. ^{{cite web |url=http://martinfowler.com/articles/mocksArentStubs.html#CouplingTestsToImplementations |title=Mocks Aren't Stubs |last=Fowler |first=Martin |year=2007 |accessdate=2010-12-29 }} 5. ^{{cite web |url=http://monkeyisland.pl/2008/02/01/deathwish/ |title=Death Wish |last=Faber |first=Szczepan |accessdate=2010-12-29 }} 6. ^{{cite web|last=Kaczanowski,|first=Tomek |title=Mockito - Open Source Java Mocking Framework|url=http://www.methodsandtools.com/tools/mockito.php| accessdate=2013-09-17}} 7. ^{{cite web |url=http://monkeyisland.pl/2008/01/14/mockito/ |title=Mockito |last=Faber |first=Szczepan |accessdate=2010-12-29 }} 8. ^{{cite web |url=https://code.google.com/p/mockito/ |title=Mockito Home Page |accessdate=2010-12-29 }}