EasyMockMock object Framework For java development
Unit tests in JavaMain framework Junit Since version 4 annotationConcurrent TestNGUnit test coding is important to prove the quality of your project
DBUnit for project with databaseIt becomes difficult to test complex systemDBUnit allow us to refresh the content of the database and to prepare data for a testProblem number of xml files may increases following the numbers of testsAre the tests really „unit“ ?
What is mock ?
Mock objectsUnit tests are white box tests The developers is allowed to look at the codeMock objects replaces the objects linked to the object we want to testIt becomes possible to test more path (exceptions, errors)We have to change a little the implementation to make the mocking easier
Features of mock frameworkMain features Value returning for a stubbed method Exception throwing for a stubbed method Invocation check method Method arguments check Invocation order for one mock checkAdvance features Stubbing of equals() and hashCode() methods ...
Advantages /DisavantagesAdvantages Test easier to write More confidence on the tests Tests faster Increase of code coverageDisavantages Learn a tool (no common syntax) Tests are more unit tests so we need higher level of tests
Mock frameworks in JavaOpen projects well know EasyMock MockitoOthers Jmock SevenMock Jmockit Rmock Unitils ...
Comparison EasyMock / JMockEasyMock Record Mock Replay themJMock Write expectation as you go
Why choose EasyMock?Free Licence ApacheLong experience since 2001 But still alive (version 3.1 in 2011)Clear syntaxeMain feature of mock coveredChoosen by my company
Live cycle of a Mock objectCreate a mockSet up your expectationSet the mock to replay mode Call your code under testVerify that your expectation have been set
Create a mock (Nice to Strict)Create a mock CreateNiceMock() Unexpected returns an empty value (0 or null) CreateMock() The order of the call is not checked CreateStrictMock() The order of the call is checked