小编Byt*_*yte的帖子

How to test logging in junit5?

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();
Run Code Online (Sandbox Code Playgroud)

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!

java testing logging junit-rule junit5

9
推荐指数
3
解决办法
5921
查看次数

标签 统计

java ×1

junit-rule ×1

junit5 ×1

logging ×1

testing ×1