[英]Running HUnit tests with Hspec
我想在規范內運行HUnit測試:
module SHCSpec (spec)
where
import Test.Hspec
import Test.Hspec.Contrib.HUnit
import Test.HUnit
import SHC.Types
import SHC.Lix
spec :: Spec
spec = do
fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
[ Irrelevant @=? toHit []
, None @=? toHit [False]
, None @=? toHit [False, False]
, Partial @=? toHit [False, True]
, Partial @=? toHit [True, False]
, Partial @=? toHit [False, False, True]
, Partial @=? toHit [False, True, False]
, Partial @=? toHit [True, False, False]
, Full @=? toHit [True]
, Full @=? toHit [True, True]
])
上面的代碼可以工作,但是會產生以下丑陋的輸出:
SHC
SHC.Lix
toHit
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
<unlabeled>
是否可以將標簽toHit
到每個測試用例上? 像這樣:
SHC
SHC.Lix
toHit
toHit
toHit
toHit
toHit
toHit
toHit
toHit
toHit
toHit
更好的方法是在每個toHit
案例toHit
附加一個數字。 我搞砸了TestList
並map TestLabel
無濟於事。
如何使用以下功能將標簽附加到所有測試中:
label ts =
[ show i ~: t | (i,t) <- zip [(1::Int)..] ts ]
只需在您的測試列表前面加上對label
的調用即可:
spec :: Spec
spec = do
fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
label
[ Irrelevant @=? toHit []
, None @=? toHit [False]
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.