Can I make JUnit more verbose?

后端 未结 10 2035
再見小時候
再見小時候 2021-01-03 21:52

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

10条回答
  •  时光说笑
    2021-01-03 22:07

    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).

    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.

    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.

提交回复
热议问题