News for hackers. Stuff that matters.
Re:Ask HN: Devs: How did you go from writing just code, to w... by al2o3cr on Monday January 02, 2017 @08:59AM (#13301159)
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).

There are no comments on this comment yet.