As for everything, the pros and cons should be weighted to reach a practical and effective approach. For example there is rarely a need to test every single function.
Overall, I don't find this piece very insightful.
As for everything, the pros and cons should be weighted to reach a practical and effective approach. For example there is rarely a need to test every single function.
Overall, I don't find this piece very insightful.
And that's where the bugs end of being.
People suck at writing code so it needs to be reviewed by peers and thoroughly tested. If you said that in an interview for code you'd written then I'd point to the door.
> If you said that in an interview for code you'd written then I'd point to the door.
That's an extremely arrogant thing to say. Any experienced dev will understand my point, so...
> If you said that in an interview for code you'd written then I'd point to the door.
And they would be better off not having to work at a place with an intolerable environment of the kind.
class Foo{
public Foo(initialValue) {
this.value = initialValue
}
public setValue(value) {
this.value = value
}
public getValue() {
return this.value;
}
}
What's the point, what are you testing? That the language's most basic operations still work?``` public setValue(value) { this.value = value + 5 } ```
then your tests will start to fail.
Treat tests as a contract.
Of course it's also a balancing act - should you immediately write test for this? I try to.
There is a set of bugs that only higher-level testing will catch. There is another set of bugs that both higher and unit-level testing will catch. Then there is the set that only unit-level testing will catch.
How important is that last set? If a unit test fails and there is no user interaction to trigger that failure, is it really a bug?
Unit tests can be valuable if they help you during development of a unit, but most units are not that complex and should not require unit tests.
The cost of testing and debugging increases as you go down the development/release cycle.
If you have unit tests then that helps integration tests (less issues, easier to investigate), system tests, etc. all the way down to dealing with bug reports from the field.
> but most units are not that complex and should not require unit tests.
That is a very bold claim...
Not in my experience. I don't see how a unit tests helps me with bugs that show up in the field. If it shows up in the field, something should've caught it, which means testing failed.
> That is a very bold claim...
I'm a bold guy.