[英]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
。 怎么做? 还是美味的支持仅是纯测试?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.