• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Mock Object for Legacy Code

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to apply JUnit in my project but the problem is it has some very complex value objects.Some of the value objects represent report data also. I tried to use EasyMock and jMock but both of them are restricted to particular patterns (interfaces). I am restricted to change the design.
Please suggest me how can I take full advantage of JUnit and mock object. Thanks in advance.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the class extension for EasyMock, for example? It allows you to mock concrete classes, too.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also have some success in mocking concrete classes by extending them and overriding non-private methods.
 
Himanhsu Yadav
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
Have you looked at the class extension for EasyMock, for example? It allows you to mock concrete classes, too.



How about jMockit?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Himanhsu Yadav:
How about jMockit?


Yes, JMockit seems to support mocking classes, too. Even JMock has its ClassImposteriser, which can be used to mock classes. Also, there's JRetrofit, which might become useful in some situations.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another alternative might be to introduce Sensing Variables in your production classes.

I highly recommend the book "Working Effectively With Legacy Code", which talks explicitly about how to write tests for hard to test code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic