1

I'm writing a nodejs npm module that needs a mySQL database to operate.

I would like to write a test module that connects to a "fake" database and do some operations on it.

I already have setup my test database locally in my developing machine, but I would like this tests to work in any machine.

What's the best practice for writing integration tests modules that depends on an operating mySQL database?

Does exists any public service in the net where I can get a temporary mysql user/password where I can do some operations for a limited time/size?

jbaylina
  • 4,408
  • 1
  • 30
  • 39

2 Answers2

4

Usually you would set up a continuous integration (CI) system that executes your tests everytime you commit a change to your version control system. The CI system would provide a clean MySQL database your tests will run against. If you use a CI system in the cloud you often can easily configure it to provide the database. E.g. see Travis CI.

If you set up a CI system other developers will still need to run their own MySQL database on their computer if they want to execute the tests. Alternatively, you may use a mock instead of the real database in your tests. For details see: How do you mock MySQL (without an ORM) in Node.js

However, using a mock won't give you sufficient test results since the mock just emulates the database in a simple way. Sometimes the mock may be too simple or just be buggy. So you will need to run at least some of your tests also against the real database. Thus you may choose to run the tests against the real database with your CI system and run the tests against the mock during development.

Community
  • 1
  • 1
analog-nico
  • 2,750
  • 17
  • 25
0

Not quite fully understanding the question I would suggest Amazon RDS for short lived testing where accessing something over the public internet is required. Amazon web services can get pricey quick if used for any real traffic but still a good option for any proof of concept.

evillive
  • 181
  • 1
  • 4