用值填充 MySQL 数据库
我的笔记本电脑上有一个本地安装的 MySQL 服务器,我想使用其中的信息进行单元测试,所以我想创建一个脚本来自动生成所有数据。我正在使用 MySQL Workbench,它已经生成了表(从模型)。是否可以使用它或其他工具来创建自动脚本来填充数据?
编辑:我现在发现我不清楚。我确实有对单元测试有意义的数据。当我说“自动生成所有数据”时,我的意思是该工具应该获取我今天在本地数据库中拥有的有意义的数据,并创建一个脚本以在其他开发人员的数据库中生成相同的数据。
I have a locally installed MySQL server on my laptop, and I want to use the information in it for a unit-test, so I want to create a script to generate all the data automatically. I'm using MySQL Workbench which already generates the tables (from the model). Is it possible to use it, or another tool, to create an automatic script to populate it with data?
EDIT: I see now that I wasn't clear. I do have meaningful data for the unit test. When I said "generate all the data automatically", I meant the tool should take the meaningful data I have in my local DB today and create a script to generate the same data in other developers' DBs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有用的单元测试是那些反映您期望或在实践中看到的数据的单元测试。泵入充满随机位的模式并不能替代精心设计的测试数据。正如 @McWafflestix 所建议的 mysqldump 是一个有用的工具,但如果您想要更简单的东西,请考虑使用 使用 INFILE 加载数据,从 CSV 填充表格。
其他一些需要考虑的事情:
更新
如果您在Java环境中,dbUnit是一个很好的解决方案:
The most useful unit tests are those that reflect data you expect or have seen in practice. Pumping your schema full of random bits is not a substitute for carefully crafted test data. As @McWafflestix suggested mysqldump is a useful tool, but if you want something simplier, consider using LOAD DATA with INFILE, which populates a table from a CSV.
Some other things to think about:
Update
If you're in a Java environment, dbUnit is a good solution:
您可以使用默认值填充(如果已定义)
You can populate with defaults (if defined)