我可以让JUnit更详细吗? [英] Can I make JUnit more verbose?

查看:119
本文介绍了我可以让JUnit更详细吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当assert语句成功,或者至少让它显示遇到的成功断言语句的数量时,我想让它大喊大叫。

I'd like to have it yell hooray whenever an assert statement succeeds, or at the very least have it display the number of successful assert statements that were encountered.

我正在使用JUnit4。

I'm using JUnit4.

有什么建议吗?

推荐答案

如果你想看到每个成功断言的一些输出,另一个不需要外部依赖或源代码的简单方法就是定义你自己的Assert类,它将所有方法委托给标准的JUnit Assert类,以及记录成功的断言(失败的断言将通常由JUnit类报告。)

If you want to see some output for each successful assertion, another simple approach which requires no external dependencies or source code, would be to define your own Assert class which delegates all methods to the standard JUnit Assert class, as well as logging successful assertions (failed assertions will be reported as usual by the JUnit class).

然后从org.junit.Assert对测试类运行全局搜索和替换>com.myco.test.Assert,它应该修复所有常规和静态导入语句。

You then run a global search-and-replace on your test classes from "org.junit.Assert" => "com.myco.test.Assert", which should fix-up all regular and static import statements.

然后你也可以轻松地将你的方法迁移到更安静的-is-better-camp并更改包装类以报告tota l每个测试或每个类传递的断言数等等。

You could also then easily migrate your approach to the quieter-is-better-camp and change the wrapper class to just report the total # of passed assertions per test or per class, etc.

这篇关于我可以让JUnit更详细吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆