dimanche 7 janvier 2018

Best practices for testing websites with NodeJS

I'm currently working on a website using NodeJS with Express, MySQL backend and some cronjobs. I think everything works as expected, but I want write tests for the future to ensure that the website is working correctly. At the moment I'm using mocha, chai and Zombie to do some simple tests and installed strider for test & deployment. But now, I'm a bit confused what are the best pratices for website tests.

I mean I can write unit tests for my stored procedures in MySQL, I can write tests to access the front-end using Zombie and so on. But I've not that much experience in testing websites. I'm especially confused about:

  1. How to test my stored procedures? Is it better to test them directly (in MySQL) or is it better to test them in NodeJS? For example: I can write other stored procedures to test stored procedures, but I can also write tests in NodeJS to test my stored procedures. From my point of view it's better to use NodeJS because I'm stored procedures that return a result-set and in MySQL I cannot test such stored procedures. What do you think?

  2. Is it better to test single components or the entire website (with sample data in my database)? The problem is, that there're not that much single components because nearly everything is encapsulated in Express callback functions to handle get/post requests. So in my opinion it makes no sense to test single components. Or... is it better to separate the encapsulated callbacks from Express for better testability?

  3. How to test cronjobs that access external resources (fetching prices every 30 minutes or similar)? I'm thinking about writing a counterpart to test such cronjobs but is it necessary?

  4. What's your test strategy/experience in testing websites?

Sure there're much articles about testing in NodeJS but I don't know... I think some of the articles showing it only to show that it is possible, but nothing more. So, I hope there're some users out there to answer my questions :)

Aucun commentaire:

Enregistrer un commentaire