是否可以跳过 HSpec 测试套件中的测试?

问题描述 投票:0回答:2

在大多数编程语言中,在某些情况下很容易跳过测试。在基于 Haskell HSpec 的测试套件中是否有正确的方法来做到这一点?

haskell hspec
2个回答
5
投票

it
更改为
xit
将相应的规格项目标记为待处理

来源: https://hackage.haskell.org/package/hspec-2.11.7/docs/Test-Hspec.html#v:xit


2
投票

如果我理解正确的话,HSpecCore对于这种情况没有特殊的解决方案。但是您可以跳过测试而无需详细说明。例如:

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}
© www.soinside.com 2019 - 2024. All rights reserved.