I am transitioning from junit4 to junit5 on a project and trying to figure out how to test logs. Previously, I used
@Rule
OutputCapture outputCapture = new OutputCapture();
and would then write an assertion using outputCapture.toString(), for example
assertThat(outputCapture.toString(),containsString("status=200"));
Since @Rule annotation hasn't been implemented yet in junit5, I can't use outputCapture. Any ideas what to do instead? Thanks!
The Migration Tip from the JUnit5 documentation clearly states that -
For the purpose of using the existing
@Rulesupport from JUnit 4, there is though a way suggested for method or class level annotations.A better option would still be redesigning your test suite to use the Extension Model from JUnit5 if you're using it.