• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Mock Object for Legacy Code  RSS feed

 
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: 106
  • 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.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!