How to test main class of Spring-boot application

后端 未结 9 1860
心在旅途
心在旅途 2020-12-03 00:18

I have a spring-boot application where my @SpringBootApplication starter class looks like a standard one. So I created many tests for all my functi

9条回答
  •  时光取名叫无心
    2020-12-03 00:51

    I solved in a different way here. Since this method is there only as a bridge to Spring's run, I annotated the method with @lombok.Generated and now sonar ignores it when calculating the test coverage.

    Other @Generated annotations, like javax.annotation.processing.Generated or javax.annotation.Generated might also work but I can't test now because my issue ticket was closed.

    package com.stackoverflow;
    
    import lombok.Generated;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
    
        @Generated
        public static void main(String... args) {
            SpringApplication.run(Application.class, args);
        }
    
    }
    

提交回复
热议问题