如何“参数化” Clojure Contrib 的测试是什么?
Junit 和 TestNG 提供了迭代输入参数集合并针对它们运行测试的机制。在 Junit 中,这是通过 支持的参数化注解,而TestNG使用@DataProvider。
如何使用 test-is 库编写数据驱动的测试?我尝试使用 for 列表理解来迭代输入参数集合,但由于 deftest 是一个宏,因此它需要 is 子句。
Both Junit and TestNG provide mechanisms for iterating over a collection of input parameters and running your tests against them. In Junit this is supported via the Parameterized annotation, while TestNG uses @DataProvider.
How can you write data-driven tests using the test-is library? I tried using for list comprehension to iterate over an input parameter collection, but because deftest is a macro it's expecting is clauses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从阅读有关 Junit 中参数化测试的文章来看,一旦您通过了样板,参数化最酷的部分就是它可以让您输入以下内容:
并轻松定义四个测试。
在 test-is 中,是等效的(不需要样板代码)宏是
are
如果您想将输入作为映射提供,那么您可以运行类似的命令:
虽然
are
> 宏将产生更容易阅读的输出。From reading the article on parameterized tests in Junit it seems that once you get past the poiler plate the cool part of parameterization is that it lets you type this:
and easily define four tests.
in test-is the equivalent (no boiler-plate code required) macro is
are
If you want to give your inputs as a map then you could run something like:
though the
are
macro will produce more easily read output.不确定我是否理解参数化测试的意义,但我会为此使用动态绑定。
您可以自己重写
deftest
和run-tests
。让测试以其他方式接受参数可能需要十几行 Clojure。Not sure I understand the point of parameterized tests, but I would use dynamic binding for this.
You could rewrite
deftest
andrun-tests
yourself. It'd be maybe a dozen lines of Clojure to let tests accept parameters in some other way.