Re:Programmers Should Never Trust Anyone, Not Even Themselves
by bluGill on Monday July 01, 2024 @09:09AM
(#40845512)
Unit tests testing the API - if there is no API there then the level of unit it probably too low. The purposes of all tests is to say "No matter what this will never change" - while never is a bit to strong as you are allowed to make changes any API that your unit tests covers will be painful to change, both because the tests will also have to change and so you have nothing to guide you, and also because odds are you don't have good coverage from other tests (integration tests would catch issues, but you rarely have all cases covered).
Or to put it a different way, your unit tests should cover units that have a good boundary to the rest of the system. This should sound like a module, but there is reason to have module as a larger thing than your unit (most of the time there shouldn't be, but once in a while this is useful), and so while there is overlap it is often useful to consider them different.
Integration tests cover the API, but they do not test the API (well they often use some API as well, but the won't cover all your internal APIs.)
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by matt_j on Monday July 01, 2024 @08:59AM
(#40845432)
API doesn't imply integration. Consider any module or package to have an API exposed to the user of the package. Unit tests should assert that the package behaves as expected.
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by bluGill on Monday July 01, 2024 @09:15AM
(#40845573)
By users I assume you mean other developers who use the API (including you next week). It would be better to use a different term as often user means "end user" or "customer" and not internal users.
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by matt_j on Monday July 01, 2024 @09:26AM
(#40845666)
Yeah, I'm not sure what the better word is. As a programmer, I use APIs. "interact with", "code to/against". I think "user" is OK. We're all users at different levels of abstraction.
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by randomdata on Monday July 01, 2024 @09:07AM
(#40845496)
That's exactly what Beck described when he originally coined the term.
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by thfuran on Monday July 01, 2024 @08:59AM
(#40845428)
Your units don't have some interface through which they interact with other units?
Re:Programmers Should Never Trust Anyone, Not Even Themselves
by bobthepanda on Monday July 01, 2024 @01:05PM
(#40847797)
API is accesible public interface, I feel like I’ve seen it used to talk about accessible “to the public/other teams” from a service standpoint but not to describe any sundry public methods of a file.
You’re talking about integration tests or e2e tests.
Those don’t sound like unit tests.