Maybe i can try catching exception? but what else can i possibly test
so that JUnit will test out SpringApplication.run()? any example is
appreciated. Thank you all!
Making the test fail if an exception is caught is here helpless as a thrown exception during a test has already as consequence to make the test fail (in error more precisely).
If you execute already test classes that load the whole spring boot context (@SpringBootTest
) you don't need to write a test to check that it is correctly loaded.
You should test the Application
class if it has some logic.
For example you could declare a method annotated with @Before
that does some processing after the context is loaded and you would like to assert that the processing is done as it should done. Other example : you could pass some arguments in the main()
method and you would like to assert that the arguments are used by the method as expected.
All that is testable with @SpringBootTest
.
If your Application
class does nothing but :
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
but you need all the same to cover the main()
test method to be compliant with some coverage tool or organization, create an integration test for that, document it clearly and let the integration continuous does that because loading a Spring Boot application takes time. You can refer to this question.