JUnit test for System.out.println()

前端 未结 13 1708
广开言路
广开言路 2020-11-22 03:18

I need to write JUnit tests for an old application that\'s poorly designed and is writing a lot of error messages to standard output. When the getResponse(String reque

相关标签:
13条回答
  • 2020-11-22 04:12

    You cannot directly print by using system.out.println or using logger api while using JUnit. But if you want to check any values then you simply can use

    Assert.assertEquals("value", str);
    

    It will throw below assertion error:

    java.lang.AssertionError: expected [21.92] but found [value]
    

    Your value should be 21.92, Now if you will test using this value like below your test case will pass.

     Assert.assertEquals(21.92, str);
    
    0 讨论(0)
提交回复
热议问题