mockito is a pretty cool mocking framework. It is simple and logic… actually i am using it with interfaces, which makes it really logic and simple, dont know, who it works against normal classes… will test that soon 🙂
but first, how does it work with a simple calculator class:
HelloWorld helloWorld = Mockito.mock(HelloWorld.class);
Mockito.when(helloWorld.hello(Mockito.anyString())).thenReturn(“Hello”);
- So first line initializes the mock.
- Second line defines the return value of the function hello(String) when called with any string. So it allways returns Hello.