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.
我有一个用nodejs构建的web应用程序,我想对我的API进行一些集成测试,这将涉及到访问实时数据库。
Is there any easy way to load & execute an SQL dump file to pre-populate the database before running my tests?
在运行我的测试之前,是否有简单的方法加载和执行SQL转储文件来预填充数据库?
2 个解决方案
#1
2
You could group your sql queries for restoring your databases in any teardown or tearup events when needed.
您可以对sql查询进行分组,以便在需要的时候在任何拆解或拆解事件中恢复数据库。
you might want to use any kind of flag before running your tests that needs a clean "data structure"
在运行需要干净的“数据结构”的测试之前,您可能需要使用任何类型的标志
#2
1
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
#1
2
You could group your sql queries for restoring your databases in any teardown or tearup events when needed.
您可以对sql查询进行分组,以便在需要的时候在任何拆解或拆解事件中恢复数据库。
you might want to use any kind of flag before running your tests that needs a clean "data structure"
在运行需要干净的“数据结构”的测试之前,您可能需要使用任何类型的标志
#2
1
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