在文件中存储测试数据的最佳格式是什么? [英] What is the best format to store test data in a file?

查看:32
本文介绍了在文件中存储测试数据的最佳格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们使用存储在 .sql 文件中的测试数据,我们有时会调用这些文件来使用这些测试数据重新创建数据库.在这个文件中,我们像这样存储数据:

In our project we use test data that is stored inside .sql files that we call sometimes to recreate the database with these tests data. In this file, we store the data like this :

Insert into Table1 ('col1', 'col2') values ('val1', 'val2');
Insert into Table1 ('col1', 'col2') values ('val3', 'val2');
Insert into Table1 ('col1', 'col2') values ('val4', 'val2');
...

问题是当我们添加或删除列时,我们必须遍历所有文件(在我的例子中,有很多大文件)并手动添加列和相应的值:这是一个很大的大脑疼痛.

The problem is when we add or remove columns, we have to go through all the file (in my case, there are many big files) and manually add columns and corresponding values : it's a big pain in the brain.

所以我在想,其他人如何存储他们的测试数据?我认为使用 .yml 文件(键值对)的 rails 方式是个好方法,但是您如何在非 ruby​​-rails 环境中使用它?

So I was thinking, how do other store their tests data ? I think rails way, with .yml files (key values pairs) is the good way, but how do you work with it in a non ruby-rails environment ?

例如在导轨中:

david:
 name: David Heinemeier Hansson
 birthday: 1979-10-15
 profession: Systems development

steve:
 name: Steve Ross Kellock
 birthday: 1974-09-27
 profession: guy with keyboard

推荐答案

如果新列是架构中的非空/必需列,那么我可以看到更新数据填充 sql 脚本的问题.但是,如果新列与特定测试无关,则相应的 sql 文件应该能够忽略架构更新.

If the new columns are non-null/required columns in the schema, then I can see the problem in updating the data population sql scripts. However if the new columns are not relevant to the particular test, the corresponding sql file should be able to ignore the schema update.

另一种方法可能是

  • 维护一个预先填充了已知值的测试数据库.创建一个副本并每次针对该副本运行您的测试.每次测试运行后丢弃.
  • 每次更新架构时,都可以像在 rails 中一样通过迁移脚本进行更新.然后,这些脚本也可以针对测试数据库运行,而且工作量相对可以忽略不计.

这篇关于在文件中存储测试数据的最佳格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆