Question

I'm just starting to grasp BDD and RSpec and one thing I'm really having trouble with is figuring out how thorough I should be with my testing.

I'm just not understanding how fine-grained my testing should be to still be useful but not double development time.

Is it just a matter of preference? Or is there some general standard for what should be tested?

Was it helpful?

Solution

There's a few factors to consider here.

  1. Spec coverage should be greatest for the most important features and the things most likely to break.
  2. Specs should express developer intention. Don't write specs for trivial things you or someone else might change later.
  3. Test behavior not implementation. You should be able to change the internal implementation of a class and still pass the specs. This makes refactoring easier.
  4. Any time you fix bugs add specs to prevent the bug from regressing.

I find it helpful to think of Tests/Specs as a safety net. I want a spec to fail if another dev (or myself) breaks something that I spent time to make work. I don't want them to have to spend a lot of time changing specs for things that don't really matter. I also don't want to inhibit them from improving the application because of specs that test things that weren't important to me when writing the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top