Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Notorious H.P.B.
Jun 19, 2006

by Y Kant Ozma Post
I have what's probably a really dumb question about unit testing and mocking. Is it possible to mock an object inside a class that doesn't have getters and setters? Right now I'm trying to write a unit test for a class that submits an XML feed to Amazon.com's marketplace web service. The problem is the class was designed to be totally self-contained. Normally all of our services are written with web service objects configured through Spring, so it's easy to pass a mock object in the unit test instead of directing it to the normal Spring configuration. In this case, the web service object is set up within the class I'm trying to test itself. We don't want to hit the actual service--just test that the code is working properly and is submitting the correct XML at the end of its process. Ideally, I could use a mock web service to "receive" the XML. What can I do here, aside from modifying the production code so that the web service object can be passed in?

I hope this makes sense.

Adbot
ADBOT LOVES YOU

Notorious H.P.B.
Jun 19, 2006

by Y Kant Ozma Post
Thanks! That's great to know in case I'm trying to test with these restrictions again. For now though, I got permission to modify the production code. This definitely seems like it will be useful, however. I can already think of a few test cases that this will make possible.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply