DEV Community

Discussion on: I need to start writing test, any tips?

Collapse
 
recursivefaults profile image
Ryan Latta

My advice to get comfortable with testing would be to do this:

Pick a really small project that you understand pretty well. I personally use a vending machine as a project I rebuild often.

With that simple project in mind, set to rebuilding it using what you want to try with testing. That way you'll have a way to compare your results.

If you are going to try TDD (And I very much hope you do) I will further recommend this to start even though it sounds ridiculous.

  1. Start with a test file
  2. Write a test describing what you intend for some small part of your project to do.
  3. Watch it fail
  4. Put just enough code in the same file to make it pass
  5. Refactor - Only by move and extract.

You'll wind up doing TDD in one file at first, but it'll get you moving and a feel for the process. Do this for 45 minutes - 2 hours. Stop and look at the code you wrote, the tests you wrote, and see what you think of the results.

Collapse
 
fultonbrowne profile image
Fulton Browne

great advice, I have some projects I could do that on.

Collapse
 
wolfiton profile image
wolfiton

Really good advice @RyanLatta, to start on the familiar ground first before diving deeper into tests