Matthew Phillips
Originally posted by Matthew Phillips:
The relevent classes are instantiated inside the method, so I can't pass mock objects in as parameters. What I am thinking about doing is using wrappers, with the appropriate package and class names, around the mock objects and having those in the class path.
Is that the appropriate way to use mock objects in this instance?
Originally posted by Eric Burke:
But I'd really think hard about re-designing the method to accept parameters that you can easily mock out.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
An alternative approach would be to use a Factory to instantiate the objects. Use the "real" factory by default and provide a method to set a different Factory.
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596003870/ref=jranch-20" target="_blank" rel="nofollow">Java Extreme Programming Cookbook</a>
Originally posted by Eric Burke:
As a last resort, that would work. But I'd really think hard about re-designing the method to accept parameters that you can easily mock out.
This is a great aspect of testing - it often forces you to improve your design in order to make it easily testable.
Matthew Phillips
Originally posted by Brian Coyner:
I think decoupling your code into testable modules is a cleaner approach.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Matthew Brown:
Factory won't solve his problem. Since his ObjectToTest directly instantiate the classes needed to be mocked(ie. they are strong typed)- factories won't make a difference. His issue is access.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Matthew Brown:
I don't know how we'd get the handle to the actual mock object within the class to verify stuff.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The knights of nee want a shrubbery. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|