我有一个应用程序,它使用“spring.profiles.active”
来决定要使用哪个配置文件。我们正在使用 JUnit 4。我需要根据使用的配置文件调整我的测试类。因此,如果 "spring.profiles.active"= "X"
我需要在 A 类中执行测试,如果 "spring.profiles.active"= "Y"
我需要在 B 类中执行测试。
我尝试过使用
@IfProfileValue(name="spring.profiles.active", value="X")
但是带有上述注释的类永远不会被执行。
System.Properties()
System.getProperties(){java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=<<Masked>>, java.vm.version=25.191-b12, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=US, user.script=, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=<<Masked>>, java.runtime.version=1.8.0_191-b12, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, , os.arch=amd64, spring.profiles.active=X
最佳答案
希望您在类(class)级别添加了 @IfProfileValue(name="spring.profiles.active", value="X") 。 尝试在类中添加测试方法并检查。
关于java - 基于 Spring 配置文件的条件 JUnit 4 测试执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56833577/