How to unit test logging error with Spock framework in groovy

前端 未结 2 1333
日久生厌
日久生厌 2020-12-17 00:45

So I have a class that has a method that logs a message:

class Car {
    private Logger logger = LoggerFactory.getLogger(Car.class);


    void startCar() {
         


        
2条回答
  •  抹茶落季
    2020-12-17 01:03

    My Loggers are private static final so I cannot use solution mentioned above and rather not use Reflection. Alternative below.

    If you are using Spring, you have acces to OutputCaptureRule.

    @Rule
    OutputCaptureRule outputCaptureRule = new OutputCaptureRule()
    
    def test(){
    outputCaptureRule.getAll().contains("")
    }
    

提交回复
热议问题