3 ms·
The thing about unit testing existing code is that it is much easier than most people think: https://michaelfeathers.silvrback.com/characterization-testing http
by michaelfeathers 10y ago
The thing about unit testing existing code is that it is much easier than most people think: https://michaelfeathers.silvrback.com/characterization-testing https://michaelfeathers.silvrback.com/characterization-testi...
- recursive 10y agoThat doesn't even address the hard part. That link shows how to add tests for a nice pure function. The reason testing existing code is usually hard is that it's inserting records in a database or launching nukes or something, and we're not able to actually do those things in a unit test.
- AnimalMuppet 10y agoOf course not, at least not for the launching nukes. Inserting records in a database? I unit test that all the time. You just need a database on your development machine, rather than accessing the production database.
- recursive 10y agoYou need a database, a way to access it, and some kind of guaranteed initial state, and a way to tell your code to use that stuff instead of the production database. There's no guarantee that some arbitrary existing code base will provide a sane way of providing those things.
- AnimalMuppet 10y agoAn arbitrary existing code base? Perhaps not. The portions I've been working on for any length of time? They will. They'll have unit tests, too. Some kind of guaranteed initial state? Yeah, my tests will set that up every time they run, just like they'll set up everything else they need. Now, if I'm working on Oracle-specific code, say, and I don't have an Oracle license for my desktop, I'm unable to do what I have so bravely stated that I will do. Also, if I'm thrown into a mess with no time to do anything but panic fixes, I don't have time. But never in my career has that been the case for long (maybe I'm fortunate...)
- michaelfeathers 10y ago> That doesn't even address the hard part. Fair enough. I did write a book on the other parts, though. https://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/B005OYHF0A https://www.amazon.com/Working-Effectively-Legacy-Michael-Fe...