Common Mistakes Developers Make
thenextweb.com
thenextweb.com
I was watching some anime last night where the characters were trying to make a computer game for some contest. They finished it, but it was too buggy to play through to the end without crashing (or causing the computer to restart, not sure how they managed that one), and they decided it would be impossible to fix them all because the game takes five hours to play through all the way.
This is a common error, not one committed at random by a bunch of fictional high school students. You should never need to use your program to check that it doesn't crash after you've made changes. Your tests should cover this. If you're loading up your web browser to see if your sort routine works, you're wasting your time again and again. You have a computer that can be programmed to do anything you want. Tell it to do what you would do if you were playing your game or using your website. Then it can test your code thousands of times a second, instead of once every five hours.
</rant>
This is also a good check to see if your code is reusable. If you can't reuse parts in isolation to test your program, you're probably not going to be able to reuse them in another program.
I don't disagree that tests (especially fuzz tests) are essential, but this is a problem with dynamic and unsafe (unrestricted side-effects) languages, not languages in general. You're very unlikely to write a program in a language like Haskell, have the program compile, and then not work as expected.
is_palindrome :: String -> Bool
is_palindrome _ = True
You still have to test it.I never said that you didn't need tests at all, or that you couldn't deliberately write programs that didn't work. I'm just of the opinion that the heightened focus on unit tests is a symptom of a language that doesn't perform such checks for you automatically.
I also very strongly disagree with your insinuation that you need unit tests. Fuzz tests can be much more powerful.
Having also written a lot of Python, I don't find my software dying unexpectedly from AttributeErrors. Instead, it merely produces the wrong answer because the wrong code was in the method.
The advantage the compiler brings is the ability to refactor. With tests, you don't know if you've gotten everything. But if you change a method signature in, say, Java; you'll know immediately when you run the compiler. But it doesn't mean your program will produce the right answer, it only means that you're calling the function with the right number of arguments of the right types.