2

I'm tyring to make unit tests for my node application. I'm using a postgresql database for the development and SQLite for the tests. However Sqlite does not understand some features of postgresql such as to_tsvectorand sometimes I got a problem of SQLITE databse locked. So I think for a server to test the application on local and on build sever. Is it a good solution to do that? I found some alternatives that mention to use docker container testing with docker.

So what are the suitable solution to run postgres test on local and server build without getting problem of databse lock?

Slim
  • 3,120
  • 4
  • 30
  • 54

1 Answers1

2

I would avoid using the database in the unit tests as they are now dependant on an external system:

Part of being a unit test is the implication that things outside the code under test are mocked or stubbed out. Unit tests shouldn't have dependencies on outside systems. They test internal consistency as opposed to proving that they play nicely with some outside system.

Basically, mock any calls to the database so you don't need to use one.

However, If you really must use a Postgres database you should use the official image in a compose file and initialize it with your schema. You can then connect to that with your tests in a known state, etc.

As for the Database lock, it may disappear after using Postgres instead of SQLite and you may want to check if you have any concurrency in your tests.

syncdk
  • 2,170
  • 2
  • 21
  • 29