我現在有下面的測試代碼:有沒有可能在IO之外的monad中使用帶有測試框架的HUnit?
testUpdate :: Test
testUpdate = testCase "update does change artist" $ do
(created, Just revised, parents) <- mbTest $ do
Just editor <- fmap entityRef <$> findEditorByName "acid2"
created <- create editor startWith
let artistId = coreMbid created
newRev <- update editor (coreRevision created) expected
editId <- openEdit
includeRevision editId newRev
apply editId
found <- findLatest artistId
parents <- revisionParents newRev
return (created, found, parents)
coreData revised @?= expected
assertBool "The old revision is a direct parent of the new revision" $
parents == [coreRevision created]
where
startWith = ...
expected = ...
這有點兒工作,但它的混亂。我寧願寫一些東西,而不必返回測試中的各種東西,而是在有意義的地方給出斷言。
我看到有Assertable
類,但似乎我可能不得不重新創建一堆東西。
偉大的問題,我記得想知道爲什麼當我第一次使用它時,爲什麼每個事物都需要IO。 –
monad支持'liftIO'嗎? – hammar
@hammar它的確如此,我不確定我是如何錯過這個事實的,即我需要做的就是用'liftIO'提升這些測試。但是,我會留下這個問題,也許還有其他方法:) – ocharles