我的每个测试都附有注释
@TestPropertySource(locations = "classpath:application-test.properties")
application-test.properties
的内容以spring.profiles.active=..
开头。如果将其设置为testdev
,则会通过匹配在application-testdev.properties
中找到的属性覆盖这些属性。类似地,如果设置为testuat
,则会使用application-testuat.properties
进行覆盖。
然而,如果没有设置testuat
,则某些测试实际上是没有意义的,因此我还用@ActiveProfiles("testuat")
对它们进行了注释。当我在application-test.properties
中设置spring.profiles.active=testdev
运行时,它似乎忽略了testuat
属性,只读取了基本属性和testdev
属性。
有没有一种方法可以使用@ActiveProfiles
覆盖spring.active.profiles
?
感谢您的帮助。
spring.profiles.active=
来在每个环境中运行测试? - undefinedSPRING_PROFILES_ACTIVE
环境变量来替代在文件中设置它。然后在你的测试中设置它,并创建必要的属性文件。 - undefined