简体   繁体   中英

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?

"Changing it to xit marks the corresponding spec item as pending."

source: 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. 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. 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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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