Should I use mock or sqlite to make unit tests with database on nodejs app?

603 views
Skip to first unread message

Slim

unread,
Sep 27, 2017, 4:02:50 PM9/27/17
to nodejs
I want to make some tests of database on my node.js app. I'm currently using ORM Objection and I found Sinon to mock the model. It's not useful to test efficiently the database queries such INSERT, UPDATE, DELETE.
So is it a good solution to use sqlite to make these tests?
What are the pros and cons of mock and sqlite? 
 

DaneiL

unread,
Sep 27, 2017, 4:19:22 PM9/27/17
to nod...@googlegroups.com
Hello,
In my case i use sql during tests.

There is a basic example in this project in my github.
Mostly i did there came from ideias i got from brianc the currently developer supporting the pg (postgres-node) lib.

Here is my github


I only see pros. I couldn't figure out a proper way to trap 500 errors.
So coverage rounds about 98% -96%



--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/77848a8e-2ac4-4d38-bec1-efdd0b21a928%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
[]'s

tpx1

unread,
Sep 28, 2017, 10:35:04 AM9/28/17
to nod...@googlegroups.com
I'm not shure what you want to test, but unit test means that you test
that your unit (method) will return the correct result for the given
input. For this every dependency should be mocked and you will test if
they are called in the correct way and if your method will transform the
result, that is given by the mock in a correct way.

You can do it without mocking, but than you did not test the unit. In
this case you test only the correct integration of your full stack.


Am 27.09.2017 um 17:33 schrieb Slim:
> I want to make some tests of database on my node.js app. I'm
> currently using ORM Objection
> <http://vincit.github.io/objection.js/> and I found Sinon
> <http://sinonjs.org/> to mock the model. It's not useful to test
> efficiently the database queries such *INSERT, UPDATE, DELETE.*
>
> So is it a good solution to use sqlite to make these tests?
> What are the pros and cons of mock and sqlite?
>
> * *
>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to nodejs+un...@googlegroups.com
> <mailto:nodejs+un...@googlegroups.com>.
> To post to this group, send email to nod...@googlegroups.com
> <mailto:nod...@googlegroups.com>.
> <https://groups.google.com/d/msgid/nodejs/77848a8e-2ac4-4d38-bec1-efdd0b21a928%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages