4 ms·
It's not that it's wrong. Having confidence your code works is ultimately the goal. That said, if I just need to know code works, manual, rather than automated
by nolemurs 10y ago
It's not that it's wrong. Having confidence your code works is ultimately the goal. That said, if I just need to know code works, manual, rather than automated testing works just as well, and requires less effort.
Automated testing only shows its real value when you go back to change code that was working before. With the manual approach you'd have to retest everything to have any real confidence. With the automated approach you just run a command.
I'm a big fan of automated testing, but if I didn't expect to have to ever change code, I wouldn't bother with it.
- mistermann 10y agoJust being the devil's advocate.... > With the manual approach you'd have to retest everything to have any real confidence. This kind of implies that software development before "~tdd" was a complete disorganized gong show of quality especially where refactoring, but in fact that was not the case. There are ways of coding that are more conducive to quality than others. > With the automated approach you just run a command. Once you've written all that code, yes. > if I didn't expect to have to ever change code, I wouldn't bother with it. Usually you don't, in which case the extra effort on testing is wasted, usually.
- dpark 10y agoYou usually don't have to make changes to code once you've written it? The only time I ever find that true is when the code is throwaway (ad hoc data crunching for some purpose, scripts to automate some one time tedious process, practice projects just intense to learn a system, etc). I don't think I've ever written anything that was useful for more than, say, a week that didn't get changed later by myself or someone else. The typical claim is that code maintenance is at least 10x as long as the initial write.
- nolemurs 10y ago> This kind of implies that software development before "~tdd" was a complete disorganized gong show of quality especially where refactoring, but in fact that was not the case. The question isn't "do we need to test." Testing can just take the form of running the code manually and making sure the output makes sense, but you do need to test. The question is "do we test automatically or manually." It's the same question regardless of how good your practices are. Note that this is totally distinct from the question of whether or not to use TDD. > Once you've written all that code, yes. I've found that writing tests often doesn't take much longer than testing manually, and rarely takes longer than testing manually twice. Sure, if you obsessively try to test every possible case and input, you'll waste time, but well targeted testing doesn't have to be slow. > Usually you don't, in which case the extra effort on testing is wasted, usually. For non-trivial projects I have an average number of revisions per line of code much closer to 2 than to 1. Sure, some of the code only gets written once and never touched, but other code gets revised multiple times. If you're good at writing tests, the tests will focus on those often revised lines of code. And, again, you have to compare the effort against the effort of manual testing, not against the effort of writing code you've never run and shipping it.
- shados 10y ago"Automated testing only shows its real value when you go back to change code that was working before" end to end tests, integration tests, regression tests, etc, yeah. Unit tests though...usually no. Often if you're making any kind of significant change, the entire code paths may get refactored away or change too much and the test will get nuked anyway. And it's that kind of test that usually confuses people, so it's worth understanding. A unit test's goals are many: It proves at authoring time that the code works. It saves you the time right away of having to go through the UI or spinning up a server just to validate a function is working. It proves that you thought about specific edge cases (and if you do testing consistently, the lack of test is your evidence of unconsidered edge cases. It's documentation of all of the things you considered when writing the code. It is an example of how to use the code with all it's use case. And when you nuke a piece of code away, the failing tests are now a guide of all the cases you have to make sure are truly no longer necessary. If, in the future, you do a refactor of an implementation detail (so the existing tests are still valid), then that's bonus as you get green/red validation. But in practice, that is less common than all of the other reasons for testing. That's why the "I don't expect this to change" thing isn't really a reason for or against writing tests.
- laserDinosaur 10y ago>Unit tests though...usually no. Often if you're making any kind of significant change, the entire code paths may get refactored away or change too much and the test will get nuked anyway. That pretty accurately describes my experience with unit tests. I've been part of several projects where we had pretty comprehensive unit tests (I'd say small to medium sized projects) and I never managed to get as much use out of unit tests as I liked. After one or two big refactors most of the tests needed to be, as you said, nuked anyway. While seeing all the pretty green lights is reassuring, they are rarely working when you most need them - during large refactors which blows away big sections of code. I picture unit tests as a row of black boxes sitting on a table in certain positions. Unit tests are great when you don't move the black boxes but do change the mysterious processes are running inside them. But refactoring is rarely ever that isolated in programming since you tend to move some of the black boxes around, remove some entirely, add some new ones, change the contents. To then expect the unit tests to give you back useful information on whats broken is rarely possible. I've had more success with e2e testing using things like Selenium, but it's still frustrating as a developer to read articles about how great unit testing is (like this root comment) and never able to actually get a decent working version of it in your projects (because of the reasons mentioned by this parent comment).