简体   繁体   English

根据页面结构或 REST 操作组织集成测试?

[英]Organizing a integration tests according to page structure or REST actions?

I'm getting a little bit confused about how to organize my integration tests.我对如何组织集成测试感到有些困惑。 Right now, they are organized according to page structure:现在,它们根据页面结构进行组织:

post_pages_spec.rb: post_pages_spec.rb:

require 'spec_helper'

describe "Post pages" do

  describe "show page" do

    describe "post destruction" do

    end

    describe "edit" do

    end

  end

  describe "post creation" do

  end


end

As you can see, delete and edit are inside the show action, because they appear in the show page.如您所见,删除和编辑在 show 操作中,因为它们出现在 show 页面中。

This is another way of organizing them (based on the REST actions):这是组织它们的另一种方式(基于 REST 操作):

post_pages_spec.rb: post_pages_spec.rb:

require 'spec_helper'

describe "Post pages" do

  describe "show page" do

  end

  describe "post destruction" do

  end

  describe "post creation" do

  end

  describe "edit" do

  end
end

Which structure is clearer and easier to maintain?哪个结构更清晰,更容易维护?

Assuming you really are asking about integration tests and not controller tests, I like to organize integration tests from the users perspective, and by the type of user.假设您确实是在询问集成测试而不是控制器测试,我喜欢从用户的角度和用户类型来组织集成测试。 Ex.前任。 one file for registered users, one file for admins, one for not registered users, etc and as necessary.一份文件供注册用户使用,一份文件供管理员使用,一份供未注册用户使用,等等。

The justification for this is that I have found, as a general heuristic, that the same user types have the same prerequisites for a feature, and thus fit well together.这样做的理由是,作为一般的启发式方法,我发现相同的用户类型对功能具有相同的先决条件,因此可以很好地结合在一起。 For example, a registered user viewing a post might have a lot of scenarios focusing on CRUDing existing post content, where a non-registered user might have scenarios focusing on post recommendations.例如,注册用户查看帖子可能有很多场景侧重于 CRUDing 现有帖子内容,而非注册用户可能有很多场景侧重于帖子推荐。 Since is likely that these different perspectives would have different setups and teardowns, it is also likely that they will be easier (ie. DRY-er etc) to maintain separately.由于这些不同的视角可能会有不同的设置和拆卸,因此它们也可能更容易(即 DRY-er 等)单独维护。

Also, it reads nice :) Ex:此外,它读起来很好:) 例如:

describe "Registered User" do
  context 'creating a Post' do
    it "succeeds given all fields are filled out"
    it "displays errors to the author if a field is missing"
  end
end

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

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