简体   繁体   English

在Rails中,如何加快机械师测试的速度?

[英]In Rails, how to speed up machinist tests?

I'm replacing test fixtures with Machinist. 我正在用机械师替换测试夹具。 But using Machinist to set up test data is very slow, because whenever a test method is run some new data are made by Machinist and saved to database. 但是使用Machinist设置测试数据非常慢,因为每当运行一种测试方法时,Machinist都会生成一些新数据并将其保存到数据库中。 Is there any way to cache the data in memory so that using Machinist isn't so slow? 有什么方法可以将数据缓存在内存中,以便使用Machinist不会太慢?

Thanks, Bryan 谢谢,布莱恩

1) Try SomeModel.make_unsaved if you don't actually need it to be saved. 1)如果您实际上不需要保存它,请尝试SomeModel.make_unsaved。

2) Look for ways to create lighter versions of the objects. 2)寻找创建较轻版本的对象的方法。 Maybe you can avoid creating the associated objects. 也许您可以避免创建关联的对象。 For example: BlogComment.make(:gravatar => nil) # avoid creating the gravatar image Or if you usually need the lighter version, you could flip that around and have the regular BlogComment.make create the light object (no gravatar) whereas BlogComment.make(:with_gravatar) would do the extra work. 例如:BlogComment.make(:gravatar => nil)#避免创建图形图像,或者,如果您通常需要较浅的版本,则可以将其翻转,并使用常规的BlogComment.make创建浅色对象(无图形),而BlogComment .make(:with_gravatar)会做额外的工作。

3) Avoid offsite hits to web services (Google maps, S3, etc.) if you're not specifically doing an integration test for that service. 3)如果您不是专门为该服务进行集成测试,请避免对Web服务(Google地图,S3等)的非现场访问。 Use stubbing to prevent those methods on the object you're testing from actually connecting to the external service. 使用存根可以防止要测试的对象上的那些方法实际连接到外部服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM