Monday, September 17, 2012

EasyMock Partial Mocks FTW. (in progress)

Ever wanted to mock certain methods in a class but not all?
Unit Testing in Java got a whole lot easier when I discovered this trick.

ClassToMock classToMockPartialMock = EasyMock
.createMockBuilder(ClassToMock.class) //create builder first
//note unspecified methods are not mocked and can be called directly!

Simple and no extensions necessary.

No comments:

Post a Comment