MockitoSugar in ScalaTest provides syntactic sugar for using Mockito with ScalaTest.
In my experience, I have found Mockito to be the easiest to use among all the frameworks. It is quite easy to create a mock from ServiceClass
by simply using mock[ServiceClass]
.
Mockito leads to a very understandable test format. I think that is one of the reasons for its popularity over jMock and EasyMock.
Let us rewrite the same example from jMock and EasyMock with Mockito. It will look something like this:
// First, create the mock object val mockService = mock[ServiceClass] // Create the class under test and pass the mock to it classUnderTest = new ClassUnderTest classUnderTest.addService(mock) // Use the class under test classUnderTest.createPayroll("Person1", 1000) classUnderTest.createPayroll("Person1", 4000) classUnderTest.createPayroll("Person1", 6000) classUnderTest.createPayroll("Person1", 19000) // Then verify...