我收到以下错误:
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [solutions.nabucco.nabuccobackendservice.user.core.repository.IntegrationTestRepository integrationTestRepository] in constructor [public solutions.nabucco.nabuccobackendservice.integration.IntegrationTest(solutions.nabucco.nabuccobackendservice.user.core.repository.IntegrationTestRepository,solutions.nabucco.nabuccobackendservice.user.core.service.jpa.UserService,solutions.nabucco.nabuccobackendservice.customer.core.service.jpa.CustomerService,...shortened output....)]: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [solutions.nabucco.nabuccobackendservice.Application]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
这发生在一个集成测试中,该集成测试希望使用注入的JPA服务/仓库和通过Testcontainers的Postgres。
我希望测试能够执行并且至少到达测试的开头。但是它从来没有到达测试并且抱怨我的application.properties。我使用带有正确的@Test注解的Junit 5。我还尝试了类似的方法,使用extends而不是implements作为https://www.baeldung.com/spring-boot-testcontainers-integration-test,我发现的例子都没有通过@Autowired注入一些东西,他们都使用Junit 4。我没有一个特殊的测试application.properties,只想让它使用默认的application.properties,但我无法通过@PropertySource(classpath...)链接它:
第一次
当我删除实现时,我得到了同样的错误,所以它最终可能与测试容器无关。这是使用测试容器的代码:
第一个
1条答案
按热度按时间6rvt4ljy1#
我不明白为什么要对
PostgreSQLContainerInitializer
使用interface
,而且我也不认为JUnit5在这种情况下会执行@Testcontainers
扩展。最简单的方法可能是删除
PostgreSQLContainerInitializer
中的@Testcontainers
和@Container
注解,而只在registerPgProperties()
的开头调用postgres.start()
。