Casey Flynn
Casey Flynn

Reputation: 14038

Easiest way to import MySQL database in nodejs for integration testing

I have an web app built with nodejs and I want to do some integration testing of my API that will involve hitting a live database.

Is there any easy way to load & execute an SQL dump file to pre-populate the database before running my tests?

Upvotes: 2

Views: 3238

Answers (2)

elsanchez
elsanchez

Reputation: 46

You could group your sql queries for restoring your databases in any teardown or tearup events when needed.

you might want to use any kind of flag before running your tests that needs a clean "data structure"

Upvotes: 2

Packet Tracer
Packet Tracer

Reputation: 3924

To load the dump, in a terminal:

mysql -u youruser -p yourdatabasename < /path/to/your/dump_file.sql

type in the password.

If you want to create the dump, in a terminal:

mysqldump -u youruser -p yourdatabasename > /path/to/your/dump_file.sql

Upvotes: 1

Related Questions