Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个导致某个输入错误的函数,是否可以编写一个测试来验证该输入是否发生错误?
我在HUnit中找不到这个“断言错误”功能。它是否在 HUnit 或其他一些测试包中可用?
您可以使用标准异常处理捕获错误并断言它是否没有发生:
errored <- catch (somethingThatErrors >> pure False) handler if errored then assertFailure "Did not catch expected error" else pure () where handler :: ErrorCall -> IO Bool handler _ = pure True