Can I make JUnit more verbose?

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

    Adding some info that would have been helpful to me when I wanted JUnit to be more verbose and stumbled on this question. Maybe it will help other testers in the future.

    If you are running JUnit from Ant, and want to see what tests are being run, you can add the following to your task:

    
    

    Note that showoutput, printsummary, and enabletestlistenerevents are what helped, not the other task attributes. If you set these, you'll get output like:

    Running com.foo.bar.MyTest
    junit.framework.TestListener: tests to run: 2
    junit.framework.TestListener: startTest(myTestOne)
    junit.framework.TestListener: endTest(myTestOne)
    junit.framework.TestListener: startTest(myTestTwo)
    junit.framework.TestListener: endTest(myTestTwo)
    Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.495 sec
    

    This was useful to me when my tests were timing out and I wasn't sure which tests were actually taking too long, and which tests got cancelled because they were unlucky enough to be running when the time was up.

提交回复
热议问题