I've been developing web applications in several languages, C#, Java, Python. But being more or less of a fresher in the industry my testing background isn't great. I've written few unit tests but I still am quite confused about how to go about making it more relevant to the code I write. I'm mainly looking to understand how to develop the intuition of testing code and making it a habit. If you answer specific to how to do this in a language, I would prefer an explanation geared towards Node.js. Also would greatly appreciate if someone could link me to some resources and also talk about how CI/CD fits into the process of automating tests.
I personally don't think reading articles or books on this subject will help you much. It didn't work for me.
I have a simple suggestion for you, for every single module you write, write unit test cases first. I know that sounds weird and counter intuitive, but it is worth the hassle.
This exercise will force you to think about the problem in a different way. You will design things better, write much better & reusable code, and end up doing what you aimed for. Along with these, you will really understand what this sh*t is all about.
Once, you are comfortable doing this, go read all the books and articles in the world about TDD. You will truly understand what author meant. :)
Instead of focusing on TDD, I would recommend reading up on unit and integration testing in general. Without the knowledge of writing a GOOD unit test, doing TDD is useless.
Hi,
Some great blogs exist, but I can recommend only one
He writes about TDD and targets Node.js/JavaScript developers with excellent explanations, and he doesn't use exotic test libraries - IMO this is the best start into JS TDD.
The best place to start is with this book: TDD by Examle
One important thing to clarify here is that TDD and Unit Testing have little to do with Software QA Testing. Unit Testing and TDD are practices performed by developers to help decrease bug density in the code base and to write more flexible designs.
The main idea behind Unit Test is that it provides quick feedback on the behavior of your code, so you can quickly know if any module or method is not doing what it is supposed to. This same idea is the principle behind CI/CD process. whenever you or a team member pushes code to the code repo, the automated CI runs a build and a set of configured checks(Unit Tests, e2e Tests, etc) to ensure the application works, if it doesn't then it will revert the merge until the last stable build, thus preventing broken code into the main repo and into production systems.
TDD is a process to help you out to write good unit tests and design better code by focusing on "Test First". It is like when you where at school and your teachers put exams/tests to you. They give you a piece of paper with questions and you had to read and fill the right answers. In our case we write the questions for our code first, and then code the answer.
For more details on how to approach TDD please read:
medium.com/@MarcFly1103/buckle-up-with-tape-1bd5e… medium.com/javascript-scene/what-every-unit-test-…
Nida
Frontend Development
I know of one screencast series - it's called Let's Code Javascript By James Shore.
Let's Code Javascript