繁体   English   中英

如何在美味测试中进行IO?

[英]How to do IO in tasty test?

Tasty支持资源,因此我可以获取资源,(完全)测试与该资源相关的一些数据,然后释放该资源。 但是如何在测试功能中执行一些IO操作?

这是文档中的示例:

import Test.Tasty
import Test.Tasty.HUnit

-- assumed defintions
data Foo
acquire :: IO Foo
release :: Foo -> IO ()
testWithFoo :: Foo -> Assertion
(acquire, release, testWithFoo) = undefined

main = do
  defaultMain $
    withResource acquire release tests

tests :: IO Foo -> TestTree
tests getResource =
  testGroup "Tests"
    [ testCase "x" $ getResource >>= testWithFoo
    ]

所以我的资源是一些连接(如套接字)。 而且我需要在testWithFoo进行API调用,因此它不能仅返回Assertion而必须在IO 怎么做? 还是美味的支持仅是纯测试?

根据美味单位文档AssertionIO ()的类型同义词。

type Assertion = IO ()

这意味着您可以在测试内进行API调用而不会出现问题。

暂无
暂无

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

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