September 27th, 2020
Alternatively: How I started testing and you can too!
We should be testing our code, but it can be difficult to get started. It seems like such a giant, tangled topic. And we aren't seeing a lot of good examples of testing in different situations, because they aren't included as a matter of course in tutorials and lessons. So how do we learn? The answer always seems to be, "Look at the documentation."
But as a newbie, documentation can be a bit scary and is often confusing. So, where to start? Did I mention I love a good video tutorial? I watched a video tutorial and it gave me the courage to wander back over to my project to try writing a test.
I used Create-React-App to build the frontend, so I looked at the docs for testing and literally copy-pasted a simple test. I really didn't want to break my project. Reminding myself that git has my back, in I went!... with a failing test. Awesome. Why? I didn't know. Googling wasn't helpful, and I wanted to build a new thing. So, I put tests back in their little cupboard and opened up my terminal to mkdir a new project.
Halfway through this new project, tests come back up. Fighting back the "I'm so confused, and can we please not" feelings, I wandered over to some different test docs. How to set up the test? copy, paste, repeat. Okay, let's see what happens. And it passed. I did a little happy dance in my head and looked up some more docs. Wrote a few more tests. Some passed, some didn't, but most importantly, I got up and running.
I think there's a limit to how long you can avoid the topic. So, perhaps it's better to wade in early.
It’s not so much that you will write amazing tests the first time around, because you won’t. Sometimes things will pass or fail and it’ll take some time to figure out why. There is always a reason. And as you do more testing, things will make more sense.
It was recently recommended to me that I check out open source code to see how they do testing, in order to improve. So, I’m going to go dive into that!
Best of luck with your projects!