1

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

4

2 回答 2

4

“将其更改为 xit 会将相应的规范项标记为待处理。”

来源: http ://hackage.haskell.org/package/hspec-2.7.8/docs/Test-Hspec.html

于 2021-03-19T05:52:26.290 回答
2

如果我理解正确,HSpec 的核心没有针对这种情况的特殊解决方案。但是你可以跳过测试而不用冗长。例如:

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}
于 2016-12-07T10:11:15.797 回答