首页 文章

我应该如何在JUnit5 Spring MVC集成测试中添加环境属性?

提问于
浏览
0

我正在使用JUnit 5中的 MockMvcBuilders.webAppContextSetup() 编写集成测试 .

我'm extending with Sam Brannen' s SpringExtensionMockitoExtension . (真的,我正在使用组合的SpringJUnitJupiterWebConfig)

我在运行测试(编辑)时得到此输出:

java.lang.IllegalStateException: Failed to load ApplicationContext
BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.example.myapp.config.SomeConfig]; 
Could not resolve placeholder 'someEnvVar' in string value "classpath:/com/example/myapp/config/${someEnvVar}/custom.properties"

(这是我的应用程序所依赖的内部公司库 . )

似乎很清楚我需要在容器启动之前设置environment属性 . 但我正在努力发现如何使用JUnit5来解决这个问题 . 我想将PropertySources添加到环境中,但是为了获得环境,我必须得到应用程序上下文,并且这样做,它实例化,在我可以对它做任何事情之前出错 .

我尝试在 BeforeAllCallback 期间创建自己的扩展并获取环境句柄 .

我感觉我一切都错了,我错过了一些基本的东西 .

1 回答

  • 1

    我只需要在我的测试类上使用 @TestPropertySource 注释 .

相关问题