So I'm looking for some advice on how test a class I've written.
It intentionally consists of one public method Run()
which accepts varaibles and sets of a long running process. This method consists of numerous calls to private methods that perform specific tasks but shouldn't be public accessible.
My query is, in this case, it seems logical to unit tests all of my private methods. However lots of people suggest that testing private methods is a bad practice.
So my question is should I just go ahead and test the private methods or has anybody been in a similar situation and can suggest an alternative method? There is absolutely no way I can reliably test all of my private methods through the one public method.
Any help appreciated and apologies if my question isn't the clearest. The application is written in C# if thats of any help.
Thanks
Personally I take a pragmatic point of view for this sort of thing - that it's okay to make unit tests "white box" tests (i.e. you can take implementation details into account and test them) but don't go so far down that route that they end up being hugely brittle.
I'd make the private methods internal and test them via InternalsVisibleTo
. Also run some "black box" tests via just the Run
method... it sounds like these are really integration tests more than unit tests.
Another thing to consider is whether this really should be one class. Are the tasks separable? Would they make sense as individual classes themselves, with the current class just coordinating them?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With