3 ms·
What if you have a "module" within your private code? An example I have is in a pay computation engine. I have a public function that computes how much someone
by nicoburns 5y ago
What if you have a "module" within your private code?
An example I have is in a pay computation engine. I have a public function that computes how much someone ought to get paid for a given shift based on who was working the shift, what they were doing and a bunch of other criteria, what day they were working on, what time of day, etc.
Within that I have a private function that works a with a narrower scope that just does the pro-rata calculation for time-of-day and day-of-week. That function itself has a fairly high-level interface with a highly complex implementation. IMO it makes sense to test that function, even though that function is private and is only used by the one public function.
My point being whether it's private or public isn't really the point. The key thing is whether the functionality is self-contained and decoupled from the rest of the code with a stable interface.
- snidane 5y agoThe 'module' is a library of pay computation functions that your app uses privately. The library itself is public and could have other users, eg. you when invoking manually from cli when testing things out. Test your library code with unit tests - this is easier because it can be done in isolation feom external systems. Itegration testing of apps is difficult. Often it is sufficient to test by use - have a dev environment which is usable or test in prod if it's not a critically important app. This is often sufficient, but I'm sure testing gurus have a recipe to apply unit tests to the app itself as well. I personally prefer not to have 10:1 test to code ratio, so I keep things practical.