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
.addMockedMethod("meth1")
.addMockedMethod("meth2")
//note unspecified methods are not mocked and can be called directly!
.addMockedMethod("meth4")
.createMock();
Simple and no extensions necessary.
Monday, September 17, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment