0

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

我正在扩展 Sam BrannenSpringExtensionMockitoExtension. (真的,我正在使用组合的 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"

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

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

我尝试创建自己的扩展并在BeforeAllCallback.

我感觉我做错了,我错过了一些基本的东西。

4

1 回答 1

1

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

于 2016-10-26T22:30:12.790 回答