I am working on a spring-boot project, which is completely insignificant for me. I am currently using the @WebApplicationContext annotation to run any of my Junit tests, since I cannot get the application to load in any other way. My goal in asking this question is either to get a reportable answer on how to avoid using it, or links to projects using an applicable concept.
My specific goal: I would like to have a testing configuration that will not load the entire web application in order to test smaller services and subsets of classes.
Example: I currently have a series of 3 collectors. One for the parent and two others for the children
@Component public class ReportResponseAssembler { @Autowired private ParameterResponseAssembler parameterResponseAssembler; @Autowired private TimeRangeResponseAssembler timeRangeResponseAssembler; public ReportResponseAssembler makeResponse() { return new ReportResponseAssembler(); } }
For testing purposes, I would like to load only these 3 classes and make them appropriately insert dependencies into the parent. Sort of:
public class ReportResponseAssemblerTest { @Autowired ReportInstanceResponseAssembler reportResponseAssembler; @Test public void testPlaceHolder() { Assert.assertNotNull(reportResponseAssembler); } }
I tried to do something as follows:
@EnableAutoConfiguration @ComponentScan(basePackages = { "com.blahpackage.service.assembler" }) @Configuration public class TestContextConfiguration {}
Then, feeding this to SpringApplicationConfiguration, but even when validating, it does not detect the applicable beans for automatic injection. Perhaps I need to designate them as @Beans directly in the configuration and return new instances? Are there any other good ways? Any links to sample projects or explanations you have will be great.
Thanks for answering so much for your time.
source share