Spring
May 27, 2020

M01 Q08 How are you going to create an ApplicationContext in an integration test?

The great thing about Spring Framework is that it allows you to create the integration test much easier than without using it. The dependency injection and the Spring Frameworks additions allow easy integration testing.

To create integration test in Spring make sure that you have Spring Test in your dependencies and, for example, JUnit.

Then you need to put annotation @RunWith(SpringRunner.class) on the test class.

And also add Context Configuration to your test with a list of configs in annotation @ContextConfiguration. Or you can paste class with @ComponentScan annotation from production code.

Also, you can use @Autowired to inject bean that you need to test