在大多数编程语言中,在某些情况下很容易跳过测试。在基于 Haskell HSpec 的测试套件中是否有正确的方法来做到这一点?
将
更改为it
将相应的规格项目标记为待处理xit
来源: https://hackage.haskell.org/package/hspec-2.11.7/docs/Test-Hspec.html#v:xit
如果我理解正确的话,HSpec的Core对于这种情况没有特殊的解决方案。但是您可以跳过测试而无需详细说明。例如:
main = hspec $ do
...
when isDatabaseServerRunning $ do
describe "database" $ do
it "test some one" $ do
...
另一种解决方案可能是使用像
mapSpecItem_
这样的函数将测试结果更改为 Pending
,并带有有关跳过原因的消息。例如:
skip :: String -> Bool -> SpecWith a -> SpecWith a
skip _ False = id
skip why True = mapSpecItem_ updateItem
where
updateItem x = x{itemExample = \_ _ _ -> return . Pending . Just $ why}