How do I make sure my test runs with a specific set of beans so that the test doesn’t even attempt to load the actual context? Suppose I want to test some Mapstruct mapper. That test only needs that mapper (and I need it to be injected by Spring, don’t ask), how do I do that? @TestConfiguration
doesn’t stop Spring from attempting to load the main context, @TestConfiguration
beans simply have priority to those. How do I make and pass a context that only contains that mapper (plus whatever plumbing beans Spring needs)?
// some annotations, I guess, but nothing that will bootstrap the entire context
class CardMapperTest {
@Autowired
CardMapper cardMapper;
// test logic
}
I hoped this would work, but it doesn’t
@SpringBootTest(classes = CardMapperTestConfig.class)
class CardMapperTest {
// in the same test package as CardMapperTest
@Configuration
@ComponentScan(basePackages = "src/main/java/by/afinny/credit/mapper") // can't reach to the src directory where my mappers are
public class CardMapperTestConfig {
}