5 ms·
It's not going to produce "perfect" tests according to the test pyramid folks, but a good way to write your first tests is this: * Consider: when you make a ch
by al2o3cr 10y ago
It's not going to produce "perfect" tests according to the test pyramid folks, but a good way to write your first tests is this:
* Consider: when you make a change, how do you verify that it worked?
* Write a test that does THAT and verifies the result. Don't stress out about DRYing out setup yet, write a test that WORKS first.
* Repeat. You will start to spot places where you can apply patterns like factories etc.
* The tests you write this way will pretty much be "integration tests", with all the baggage that carries (brittle, slow, heavy). You'll want to keep an eye out for seams where you can add more focused testing - for instance, can you isolate the part that needs to be tested with "multiple types of fake data" and test the output of that?
You may also want to try this out on a side project first; adding testing an existing codebase that doesn't have any is pretty much "hard mode".
I'd also recommend checking out talks on testing from Justin Searls (@searls).