From: Stefan F. <ste...@we...> - 2012-06-06 16:33:28
|
Erik & Brett: recently I have mailed that I would like to add a mock library to support testing. At that time I preferred JMock (mostly above EasyMock). However I did reevaluate my choice again and realized that the library that suited my tastes best is Mockito. see http://code.google.com/p/mockito/ Checkout the documentation at http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html which really shows very well the very simple but powerful style used. Or compare to the first test example which I have pushed to the rails2.0 branch (ActionChangeTest.java) in the junit folder with the identical hierachy as rails below (the source code itself is under src folder). It is really easy to create mock objects by simply annotate private fields in the test classes with @Mock or directly with Player player = mock(Player.class) Verifying that a method of the mock is called (once) requires: verify(mock).method() And stubbing a method of the mock is initialized with: when(mock.method()).thenReturn(value) Avoiding using strings also ensures that autocompletion of Eclipse-IDe still works. This syntactical sugar simplifies unit tests substantially (at least in my opinion). Stefan |