I am quite a beginner in code testing, and was an assert
whore before. One thing worrying me in unit testing is that is often requires you to make public
(or at least internal
) fields that would have been private
otherwise, to un-readonly
them, make private
methods protected virtual
instead, etc...
I recently discovered that you can avoid this by using things like the PrivateObject class to acces anything in an object via reflection. But this makes your tests less maintainable (things will fail at execution rather than compile time, it'll be broken by a simple rename, it's harder to debug...). What is your opinion on this ? What are the best practices in unit testing concerning access restriction ?
edit : consider for instance that you have a class with a cache in a file on disk, and in your tests you want to write to memory instead.