I would say that 90% of the grief I have experienced building applications is the validation part - that you are actually building the right thing.
I would say that 90% of the grief I have experienced building applications is the validation part - that you are actually building the right thing.
Or when refactoring a piece of code that renders UI, write some tests to verify a couple of common cases and then refactor. Run the tests and I'll know whether the output is the same.
For me the right amount of automated testing is all about exploring the cost vs benefit boundary, which shifts with tooling and circumstance. But my firm rule now is: code must either have a firm expiration date or full test coverage. Nothing between is allowed.
So if you're going to cut back on testing, make sure your customers have agreed in writing on a date after which they should throw the code away.
I've always said that RSpec is about documentation, not testing (hence the name - it's a specification for your code).
However, recently, I've been using Minitest-spec; not quite as readable but less magic and it feels faster.
1. Write your code so that independent units of functionality (algorithms) can be tested. 2. Make sure people understand, when changing code, either a) change the tests first, or b) recognize what tests should be failing because of the change and which shouldn't.
For good, testable code combined with good tests, it should be rare that the tests start failing when you change the implementation. Admittedly, that's true in theory and can vary widely in practice.
The appropriate practices there are short iterations, frequent releases, acceptance tests, and having product people sitting next to developers.
For those wondering how unit testing relates to other practices, go read Kent Beck's Extreme Programming Explained. He's one of the people who led the current wave of unit testing adoption via jUnit. Years before the term "Agile" existed, he was on a team that found a highly productive way of working, one for which unit testing was an important foundational element. But it was just one of 12 practices they saw as necessary.
Once you have that working well and you're building what the businesspeople expect, the next step is to make the businesspeople start testing their assumptions. That's basically what the whole Lean Startup thing, minus the fad, is about: let's not just go build whatever the guy with the tie says. Let's all get evidence about what's really worth building.
It's sort of like "the first dose is free", but applied for good.