When I am doing personal projects I tend to ignore unit tests. Although I want to write tests, while coding I think it's going to consume a lot of my time and delay things. How to get rid of this feeling and always write unit tests for everything?
It's like trying to add any new habit to your lifestyle, like doing more excercise or eathing healthy. It takes time and discipline.
You have to start at some point, but the important thing is to be constant on its practice. Start by creating test for lib or utility functions you create for your projects. Try to keep test simple, focus on inputs and outputs of your functions or methods, and avoid mocks, spies and stubs the more you can.
If you wanna know more I recommend these blog posts:
medium.com/@MarcFly1103/buckle-up-with-tape-1bd5e… medium.com/javascript-scene/what-every-unit-test-…
Unit test saves a lot time when it comes to debugging. When I write crud operations in back-end or make changes to code and test cases just do crud operation to database and I can know overall app is working well. I don't need to check manually entering form in front-end and see if it working. Fillings form and doing crud operation front-end, I would prefer tests.
Simon Ruis
Crazy Noder
Jakub
Web Developer
Well, it will cost a lot of your time and to some point it will delay things. You should accept it. But it will save your ass later on, as the project grows.
I am working with a few people on a rather small web app for data visualization. It's a django project and we all are new to python and django. So our code isn't always the cleanest.
I tried to introduce TDD to the people, however it's not that easy to write tests first. Mostly because you have to think a lot about what you want to do. However we said that every feature we finish, should contain at least unit tests, before getting merged into the main branch.
It was a pain. Really. Because we were not used to it and after finishing the code and everything is working, we had to write tests and it delayed some stuff, because people had fun coding, but no fun writing tests, so some features could not get merged because there were no tests.
But then... after some time, we discovered that something isn't really working well. There were some problems in the models. And with problems I mean that this stuff was wrong coded, because of how django handle certain things. (And people not reading the documentation).
So we had to refactor like every model we had and some of the templates and views.
But because we had a pretty good test coverage it took only a few hours. And it was simply beautiful to change stuff, run the tests and see where are the problems.
After this and installing some coverage measurement tools, people liked tests way more.