簡體   English   中英

根據頁面結構或 REST 操作組織集成測試?

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

我對如何組織集成測試感到有些困惑。 現在,它們根據頁面結構進行組織:

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

如您所見,刪除和編輯在 show 操作中,因為它們出現在 show 頁面中。

這是組織它們的另一種方式(基於 REST 操作):

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

哪個結構更清晰,更容易維護?

假設您確實是在詢問集成測試而不是控制器測試,我喜歡從用戶的角度和用戶類型來組織集成測試。 前任。 一份文件供注冊用戶使用,一份文件供管理員使用,一份供未注冊用戶使用,等等。

這樣做的理由是,作為一般的啟發式方法,我發現相同的用戶類型對功能具有相同的先決條件,因此可以很好地結合在一起。 例如,注冊用戶查看帖子可能有很多場景側重於 CRUDing 現有帖子內容,而非注冊用戶可能有很多場景側重於帖子推薦。 由於這些不同的視角可能會有不同的設置和拆卸,因此它們也可能更容易(即 DRY-er 等)單獨維護。

此外,它讀起來很好:) 例如:

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