Issue
I am currently working on increasing the test coverage of a project, it is around 93% and I am working my way towards 100%.
I noticed that one of the blocks that are not being covered is the main method and it looks like this:
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Even though the application has over 90 tests, and some with the @SpringBootTest
annotation, this main method is still not covered.
Should I worry about this and make sure I get a 100% coverage? Or am I being too much of a perfectionist and certain things are just not worth to test, like the example above?
Why is the code above not being ran through the tests? Do I need to explicitly call the main method for it to be ran? I was expecting it to be called when the application starts up.
Solution
Should I aim for 100 %? Yes, always!. However having said that anything above 90% is considered good. It may not be possible to achieve a 100% in all scenarios.
Talking about "main method", since it is just used for the startup of a spring boot application and does not cover any functionality you can simply exclude the class which contains the main method from coverage in your pom.xml file using the following lines of code inside properties tag:
<sonar.coverage.exclusions>
**/com/example/test/MainApplication.java
</sonar.coverage.exclusions>
Answered By - Ashwin Shirva