简体   繁体   English

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

[英]Is it possible to skip tests in HSpec test suite?

In most programming languages it is easy to skip a test in some circumstances.在大多数编程语言中,在某些情况下很容易跳过测试。 Is there a proper way to do that in haskell HSpec based test suite?在基于 haskell HSpec 的测试套件中是否有正确的方法来做到这一点?

"Changing it to xit marks the corresponding spec item as pending." “将其更改为 xit 会将相应的规范项目标记为待定。”

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

If I understand correctly, Core of HSpec doesn't have a special solution for this case.如果我理解正确的话, HSpec 的核心没有针对这种情况的特殊解决方案。 But you can skip tests without verbosity about it.但是你可以跳过测试而不用冗长。 For example:例如:

main = hspec $ do
    ...
    when isDatabaseServerRunning $ do
        describe "database" $ do
            it "test some one" $ do
                ...

Another solution maybe to use the function like mapSpecItem_ for changing result of test to Pending with a message about why was skipped.另一种解决方案可能是使用mapSpecItem_之类的函数将测试结果更改为Pending并带有有关跳过原因的消息。 For example:例如:

skip :: String -> Bool -> SpecWith a -> SpecWith a
skip   _ False = id
skip why True  = mapSpecItem_ updateItem
  where
    updateItem x = x{itemExample = \_ _ _ -> return . Pending . Just $ why}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM