Mockito

FacebookTwitter
Mockito is a fantastic mock library for Java.

Adzic » Mockito in six easy examples

http://gojko.net/2009/10/23/mockito-in-six-easy-examples/
Today we’re going to take a look at the Mockito framework that not only does sound like my favourite summer cocktail but also offers nice testing, mocking/stubbing, test-spying features and mock injections. After that we’re going to take a look on how to mock static or final classes by extending Mockito’s capabilities with PowerMock. Prerequisites http://www.hascode.com/2011/03/mocking-stubbing-and-test-spying-using-the-mockito-framework/

Blog Archive » Mocking, Stubbing and Test Spying using the Mockito Framework and PowerMock

Mockito

package com.om.example.loginservice ; import org.junit.Test ; import static org.mockito.Mockito.* ; public class LoginServiceTest { @Test public void itShouldSetAccountToLoggedInWhenPasswordMatches ( ) { IAccount account = mock ( IAccount. class ) ; when ( account. passwordMatches ( anyString ( ) ) ) . thenReturn ( true ) ; IAccountRepository accountRepository = mock ( IAccountRepository. class ) ; when ( accountRepository. find ( anyString ( ) ) ) . thenReturn ( account ) ; LoginService service = new LoginService ( accountRepository ) ; service. login ( "brett" , "password" ) ; verify ( account, times ( 1 ) ) . setLoggedIn ( true ) ; } } http://schuchert.wikispaces.com/Mockito.LoginServiceExample?responseToken=03c7bf7d5ccafa05b51ded7c22b4382b8
http://code.google.com/p/mockito/ 06-10-2012 : Mockito 1.9.5 released! See the release notes . Should appear in maven central shortly.

mockito

Posted by Brett Schuchert on 05/27/2009

Mockito Example (Java Mocking Framework)

http://blog.objectmentor.com/articles/2009/05/27/mockito-example-java-mocking-framework

Mockito: Java Unit Testing with Mock Objects

One of the hallmarks of an experienced developer is an appreciation of the importance of unit and integration testing. http://www.developer.com/java/other/article.php/3882311/Mockito-Java-Unit-Testing-with-Mock-Objects.htm