排除 Spring Boot 测试的 spring.factories 依赖项

问题描述 投票:0回答:1

有一个父项目 A,使用 A 依赖项的项目我们将其称为 B。 除了测试用例之外,一切都工作正常。我正在使用 SpringBootTest,它从项目 A 的 spring.factories 获取所有依赖项。我想为测试用例禁用项目 B 的这些依赖项,但需要它来运行项目 B。 项目 A 的 META-INF 中的 spring.factories 文件包含 -

1. org.springframework.cloud.bootstrap.BootstrapConfiguration
2. org.springframework.boot.autoconfigure.EnableAutoConfiguration
3. org.springframework.boot.env.EnvironmentPostProcessor.

每个都有项目A的包。

我尝试使用导入注释并传递了我自己的配置。带有项目 B 基础包的 ConponentScan 注释。但没有什么真正有帮助。

java spring spring-boot spring-test
1个回答
0
投票

如果这些工厂是

A
的编译时依赖项,那么不可能仅在
B
的测试时排除它们。但是,如果在编译时不需要它们,而仅在运行时需要它们,那么您可以使用这些依赖项的
runtime
范围来解决问题。

话虽如此,我个人避免这种类型的灰盒测试。以下是可能有帮助的博客链接:https://github.com/savoirtech/black-box-system-test

© www.soinside.com 2019 - 2024. All rights reserved.