I have many different SpringBoot tests running. So far the auto configuration slices were really helpful, especially in combination with @MockBean
.
But in my current test no such slice fits and booting up the complete context using @SpringBootTest
is too slow.
Is there a way to manually set the tip of the object tree to be started with and from there spring autowires all needed beans? Or is there a way to set all needed beans manually?
In my specific case i want to test a MapStruct generated mapper (using componentModel = "spring"
) this mapper uses two other mappers, each injecting a service to do their work.
The services are provided via @MockBean
:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProductResponsibleUnitMapperTest {
@Autowired
private PRUMapper mapper;
@MockBean
private TradingPartnerService tradingPartnerService;
@MockBean
private ProductHierarchyService productHierarchyService;
@Test
public void mapForthAndBack(){
//works but takes ages to boot
}
}
I could not use constructor injection on the mappers (for the services) because MapStruct won't generate correct implementations.
How to get a Spring-Context only containing the needed beans?