-
Book Overview & Buying
-
Table Of Contents
Learning Modular Java Programming
By :
Mockito is an open source framework used in conjunction with JUnit for testing. Mockito helps in creating Mock objects to be used while testing. Mockito tests help in reducing the tight coupling by removing the requirement of the expectation specification. Mockito creates mock objects with the static method mock() provided by the org.mockito.Mockito class. In Mockito, the when() method defines the action to be taken and then Return() returns the result of the action. When() can define a method call and thenReturn() is expected to return from the method. The when() accepts the argument of the method to be invoked and the result to be returned will be the argument of thenReturn(). when() accepts the method under testing and thenReturn() returns the result which we use for assertion. Methods such as anyString(), anyInt() are used to define independent values from the methods. Mockito can be used for behavioral testing as well. In behavior testing, a certain result is expected...