1

I asked following question on enquiring about the approach I should adopt while writing tests for controllers in REST api application? Within few hours it was downvoted three times but none of the comments written on the question criticized the question or anything about. I'm still confused on what are the possible reasons that my question was downvoted

I'm writing a REST api backend in NODE js, which is based on MVC approach. My api routes directly hit the controllers, which in turn import models which are a wrapper around the methods from a library (DB ORM) called sequelize.

What will be the better approach for writing the unit tests for the controllers,

To include models, with mock DB data, in unit tests of the respective controllers To somehow mock the models and then unit test my controllers without involving the real models at all. If the second approach is better how will I achieve writing these types of Unit tests

Link to the Question

  • 1
    I assume the down-voters didn't comment; and you got a really good answer, i think the average vote of question is around -1.5, so don't be too discouraged. – esoterik Jun 21 '18 at 14:28
  • 1
    absence of response to the first comment under the question might be the reason for downvotes as explained here (I learned this rather the hard way, on my own answers and especially questions) – gnat Jun 21 '18 at 14:56
  • 2
    I think the question is very broad (and you forgot or refused to answer Robert Harveys' question). Since you got 2 votes for closing as "too broad", I guess others saw the same problem with your question. Netherless you got a broad, but good answer (and since your question triggered that answer, it now got an upvote from me). Don't take those downvotes personal, some guys here a are very trigger-happy with the downvote button. – Doc Brown Jun 21 '18 at 14:56
  • Well, the reply to comment by Robert Harvey was missed since there was an immediate comment below that helping me in finding my solution. If what you guys say is true, then isn't is very bad that people are downvoting the question not because of the quality of that but because of their ego getting hurt? – Anshul Sahni Jun 22 '18 at 6:55

You must log in to answer this question.

Browse other questions tagged .