4 ms·
The developer should be writing unit tests for their code so they can avoid small mistakes like this.
by chrisco255 9y ago
The developer should be writing unit tests for their code so they can avoid small mistakes like this.
- chrisco255 9y agoDown vote for advocating for unit tests? That's just good practice in general.
- sah2ed 9y agoI think integration tests would be more appropriate here, especially since there are different co-operating moving parts: S3 <--> EC2/Lambda.
- codedokode 9y agoIt is impractical to cover every line of code with tests (it would get too expensive). Futhermore, in this case the author would have to test production config interacting with Amazon servers rather than a piece of code. And even 100% code coverage doesn't find all possible errors.
- chrisco255 9y ago> because of a refactor, I forgot the return statement and it just continued overwriting the file again Unit tests are specifically useful for refactors. You can refactor your code and ensure that it behaves as intended. Integration tests are great, too, don't get me wrong. Either or both would have probably caught this.
- jbergens 9y agothis was a problem involving multiple parts, unit tests normally don't catches this. You need an integration/functional test and that can be much more time consuming to write for all "integrations" and code paths.
- jo909 9y agoIt was a single function that changed behavior after a refactoring. It did work where it did not need to, because the work was already done on the object. This is only hard if you don't test at all and can't already mock the object download/upload or don't have pure functions.
- jbergens 9y agoIn this case it might have helped, I didn't read the code, but in a more general case these kind of things are rarely found by unit tests. I still doubt that the triggering caused by the file change would have been found in a unit test.