Hello Everyone,
It's my first time here posting in dev.to and I have been quite interested in implementing tests in my current JavaScript project....
For further actions, you may consider blocking this person and/or reporting abuse
Welcome, nice to have you here :).
Well, one of the benefits of tests is that they tell you when something breaks. Ask yourself: when you write code, do some things break? When things break, do you immediately find out what broke and how? Or do things break which you don't notice for a while?
Tests help you because they show you what broke immediately. Then you can revert your code or fix it right away. If you think that will be helpful, then write tests, otherwise there isn't much point.
In addition, tests save you time... I'm assuming that after you code something, you spend a couple of minutes going on the browser and checking that things are working correctly. Automated tests can do that for you much faster.
In my experience, all projects benefit from testing, even if they're added late in development.
But finally, as a counter-argument, tests are difficult to get right. If you don't write them well they can actually make your project worse. Bad tests are a maintenance nightmare. They take a long time to write. They also take a long time to modify if you make changes to the code they're testing.
So overall, my personal recommendation is:
Hope that helps. Let me know if anything didn't make sense or if I should explain something better.
Yeah, I'm the guy that tests the website right after I made changes in the code and I really liked that you shared your experience in counter-argument. Thank you! I'll look into cypress or jest as my starting point.
Initially, I started testing in order to fit in the CI, and make Github commits never break things, even minor, again.
Be aware that there are different types of testing, though; including manual testing.
I haven't gotten into CI testing since I work alone on the project but I guess learning them would be great when I work on a project with a team. I'm also looking into automated tests :)
A great place to start in CI testing is to pick up a pipeline such as Travis or CircleCI. It takes a little bit of investment up front, but you save in the long run. Builds can be fired off from commits or branch merges instead of manually handing build and deployment. You can put your testing in a pipeline so your code doesn't deploy if your tests fail. Also DevOps is a great way to differentiate yourself as a developer, so building and managing pipelines see great skills to have
Welcome!
With unit tests you can check pretty easily if the software is still working correctly when packages are updated and often you find bugs you didn’t notice before when writing tests. Also it often leads to a better architecture.
But if you have a lot of code already and want to be sure that all is working e2e tests can be the faster way to go. Like with playwright or cypress.
But in my opinion unit tests are worth the effort especially in JS projects with no typing. It take some time to add them when you haven’t done it from the start, but if you have done the initial work new unit tests are added fast.
Jest watch mode or wallaby.JS for the win.
Happy Coding!
I'm looking to learn jest / cypress but I haven't heard about wallaby.js, I'll look into it. Thanks!
Should I write tests?
If I was doing testing for frontend, I would seriously look into cypress for most things and only reach for other testing framework for more logic related stuff. For example view-helpers in javascript that you have for formatting date and what not. Use jest or other unit testing frameworks for that.
It depends what kind of test you're written but you should make sure you writing meaningful tests. For example I have seen a lot react test that testing that the component renders that's it.
I don't like those kinda of tests, I would prefer acceptance tests, for most front-end related stuff and reach for unit-test only when I need it
Hi,
I believe that if they are going to add some value then they are worth adding/using. Most often I don't see the value in going back and retro fitting tests to existing code that 'doesn't get touched'.
For code that is actively build on its often good to have a strategy that touches on various areas of the SDLC lifecycle including unit, integration, functional and performance type tests to give you more breadth in what your testing might be able to expose.
As with everything this is context dependant, Ie : a highly critical application may need a lot more tests that a one page web app