【问题标题】:RSPEC: Is it possible to run other spec file inside a spec fileRSPEC:是否可以在规范文件中运行其他规范文件
【发布时间】:2015-07-27 23:01:02
【问题描述】:

我知道最好的做法是让测试独立运行。

我正在使用 Rspec 运行 Selenium Webdriver 测试。如果我为每个特定的测试用例创建和拆除用户-组-其他模型,测试运行时间会显着增加(30 分钟左右)。

所以我将规范文件分为 create_...、delete_...,并希望在一个规范文件中调用这些规范文件。这可能吗?这是设置测试的好方法还是坏方法?

类似:

create_users_spec.rb
create_user_groups_spec.rb
create_dashboard_spec.rb
==> run some tests....
delete_dashboard_spec.rb
delete_user_groups_spec.rb
delete_users_spec.rb

run_all_spec.rb => run all of the spec files above, so you can see that 
                   it needs to run in a certain sequence

【问题讨论】:

    标签: ruby selenium rspec selenium-webdriver


    【解决方案1】:

    您真的希望能够独立运行测试。在我看来,必须运行所有测试,甚至“只是”给定文件中的所有测试,这似乎是开发过程中不可接受的延迟。它还使得难以使用像 Guard 这样基于文件观察器为您运行测试的工具。

    如果之前确实需要运行某些东西,例如,每个请求规范,您可以执行以下操作:

    # spec_helper.rb
    RSpec.configure do |config|
      config.before :all, type: :request do
        # do stuff
      end
    end
    

    但也要看看你正在尝试做什么。如果您只是为测试设置模型/数据库数据,那么您需要固定装置,或者更好的是工厂。看看 FactoryGirl。

    【讨论】:

      【解决方案2】:

      也许使用context 组织测试并明智地使用before(:each)before(:all) 会提高性能。简化数据库,或使用像 FactoryGirl 这样的库也会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-10
        相关资源
        最近更新 更多