For the past few weeks, I’ve been writing about unit testing for the members of the site (and something that I plan to continue doing in the next post). It’s something that I think; if you write server-side code, you should be doing.
Of course, it’s easier for me to say it than do it so although I try to make sure I do a good job of it, there’s always room for me to improve. I say that more as a personal gut check than anything else, so I digress.
One of the concepts that often come up during testing is the idea of testing the values of private attributes. For example, let’s say that you have a setter, but you don’t necessarily have a getter for that particular value.
It’s easy to say “Well, then you need to write a getter,” but that’s not always the case. I mean what if you’re storing some information within the class that doesn’t need to be exposed to third-party classes?
How then are we supposed to write tests against that kind of data when we want to access it but don’t have the ability to do so and don’t want to compromise the integrity of our work?
That’s where reflection comes into play.