Can I make JUnit more verbose?

后端 未结 10 2037
再見小時候
再見小時候 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:15

    junit's javadoc unfortunately says that only failed assertions are recorded (http://junit.sourceforge.net/javadoc_40/index.html)

    so it seems it would not be possible

    0 讨论(0)
  • 2021-01-03 22:22

    Are you really interested in an assertion that succeeds? Normally, the only interesting assertions are ones that fail.

    Being a fervent JUnit devotee myself, I try and make the output of the tests as quiet as possible because it improves the signal-to-noise ratio when something doesn't pass. The best test run is one where everything passes and there's not a peep from stdout.

    You could always work on your unit test until it succeeds and run "grep Assert test.java | wc -l". :-)

    0 讨论(0)
  • 2021-01-03 22:22

    Hard to be done. All assert methods are static members of the class Assert, which implies that the RunNotifier (which counts the successful and failed tests) is not within reach.

    If you dont refrain from an ungly hack: take the sources from JUnit, patch them to store the current notifier in a static field of Assert when running tests such that the static methods can report successful asserts to this notifier.

    0 讨论(0)
  • 2021-01-03 22:24

    I don't think, it's the goal of JUnit to count matched assertions or print out more verbose information. If tests are atomic, you'll get most information in there. So I would review my tests.

    You're also able to establish a LogFile in JUnit. It's possible, but it will decrease test execution performance...

    0 讨论(0)
提交回复
热议问题