簡體   English   中英

Ruby - > Haskell單元和自動驗收測試

[英]Ruby -> Haskell Unit and Automated Acceptance Testing

我是一名具有多種語言背景的程序員,但最近專注於Ruby / Rails並且有興趣學習一些Haskell。 我已經在Closure中做了一些游戲(雖然很基本的東西)。

我目前開發新Ruby應用程序的首選方法是從使用Gherkin / Cucumber之類的業務價值語言開始高級測試,然后使用RSpec或Minitest等開發小規模組件。 什么是(目前)開發新Haskell應用程序最常用的類似工具集和策略?

響應者:請耐心等待我的投票和回答。 我必須在Haskell中做一些工作才能進行任何評估。 謝謝。

通常,Haskell應用程序中的事實來源是類型系統。 您可以使用quickcheck和hspec來確保您的代碼符合您的想法,但這只是一種幫助。

對於Haskell中基於故事的自動驗收測試,您有兩個主要選擇:

  • chuchu(Haskell本身的一個不完整的Cucumber / Gherkin實現, Hackage頁面
  • 使用Wire協議的Cucumber和用Ruby編寫的測試

當然,HSpec填補了基於規范的驗收測試角色。

通過使用基於屬性的測試而不是使用QuickCheckSmallcheck等庫的TDD,可以獲得更好的結果。

據我所知,Haskell沒有Cucumber類似物。 最接近您正在尋找的可能是HSpec,即RSpec-ish。

以下是HSpec網站的逐字示例:

import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)

main :: IO ()
main = hspec $ do
  describe "Prelude.head" $ do
    it "returns the first element of a list" $ do
      head [23 ..] `shouldBe` (23 :: Int)

    it "returns the first element of an *arbitrary* list" $
      property $ \x xs -> head (x:xs) == (x :: Int)

    it "throws an exception if used with an empty list" $ do
      evaluate (head []) `shouldThrow` anyException

哪個產生

Prelude.head
  - returns the first element of a list
  - returns the first element of an *arbitrary* list
  - throws an exception if used with an empty list

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM