【问题标题】:Spring @IfProfileValue should ignore test class, but it is notSpring @IfProfileValue 应该忽略测试类,但事实并非如此
【发布时间】:2025-12-03 16:45:02
【问题描述】:

因此,我正在尝试使用 @IfProfileValue 分离测试以在我的 CI 管道上运行。

我只是将此注释放在我的一个测试类上,我还没有定义该值。我只是想检查一下,当我运行mvn test 时,surefire 会忽略这一测试。

由于某种原因,测试被选中并执行。

@IfProfileValue(name = "test-profile", value = "something")
@RunWith(Parameterized.class)
@SpringBootTest
@WebAppConfiguration
public class MyTest {

【问题讨论】:

    标签: spring maven-surefire-plugin


    【解决方案1】:

    要使测试使用 Spring 上下文,您需要使用 SpringRunner 运行它们。在您的示例中,您使用 Parameterized 运行器,这使测试忽略 Spring 上下文,因此 IfProfileValue 注释被忽略。

    【讨论】: