2 ms·
Unit tests might be exhaustive in 'lines of code covered' but never in 'possible inputs'. That is, did you remember to check for null? Did you remember to writ
by Gunax 4y ago
Unit tests might be exhaustive in 'lines of code covered' but never in 'possible inputs'.
That is, did you remember to check for null? Did you remember to write a test for floating points in languages that just have generic number types?
I don't see the value in relying on unit tests to enforce types.
It might be possible, but it relies on the programmer to:
1. Remember all of the types (was this an int? Or a float? Or a int | null union?
2. Implement exhaustive tests for each type
3. Remember to update the tests when something changes.
4. When reading code, if the types emitted are not specified, having to examine the unit tests to determine the type limits.
And the advantage of this is that it saves me a few keystrokes so i can write:
X = 5
Instead of
int X = 5
- ActorNightly 4y agoHypothetically, given developer tooling, which would you prefer to make sure your code is as correct and robust as possible? 1. Language with strong type features. 2. Testing packages that automatically include fuzz tests and null tests to ensure correct behavior? Granted most of my experience in production level software involves backend services, which essentially means json transformations 95% of the time, Ive rarely ever seen an error that results in the service saying everything is ok but returning a wrong result. For example in the case of null fields, something downstream fails and errors out - this is easily caught by testing.
- Gunax 4y agoWell I would prefer to have both. I don't think we need to choose. However, I think tests are high-maintenance. Often they consume the same amount of time to write as the actual business code. I don't know how automatic null checking tests would work. Wouldn't you need to specify what happens if a null is input? In contrast, I find the cost if typing very low for the value it delivers. Unless the code is very ephemeral (like a one off script) then I highly prefer typing.
- mharig 4y ago> That is, did you remember to check for null? What static typed language, apart from SQL, does automatic null checking?
- LeonB 4y agoC#