简体   繁体   English

如何更正 Spring 引导单元测试无法在两个几乎相同的测试类之一中加载应用程序上下文?

[英]How can I correct Spring Boot unit test failed to load application context in one of two nearly identical test classes?

I am building unit tests for a Spring Boot application that will call a couple of web services.我正在为 Spring 引导应用程序构建单元测试,该应用程序将调用几个 web 服务。 One service builds a PDF and the other stores that document, and there are separate classes to call these services.一个服务构建 PDF 和其他存储该文档的存储,并且有单独的类来调用这些服务。 I'm using IntelliJ for an IDE.我将 IntelliJ 用于 IDE。

When I have a single test class to run all of my tests, things start up and work fine.当我有一个测试 class 来运行我的所有测试时,一切都会启动并正常工作。 When I have two separate test classes, the first class continues to work fine but when running the second I receive当我有两个单独的测试类时,第一个 class 继续正常工作,但在运行第二个时我收到

ERROR [main] org.springframework.boot.SpringApplication: Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name...
Could not resolve placeholder 'PDF.form.serviceURL' in value "${PDF.form.serviceURL}"

The classes are annotated with the following, for the application context to start这些类使用以下注释,以启动应用程序上下文

 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = Application.class)

What would cause one test class to run without issue, and an identical test class to fail to start the application context?什么会导致一个测试 class 运行没有问题,以及一个相同的测试 class 无法启动应用程序上下文?

In this scenario, the problem was related to the JUnit configuration in IntelliJ.在这种情况下,问题与 IntelliJ 中的 JUnit 配置有关。 Without the appropriate environment options, the context would not start correctly, causing the error.如果没有适当的环境选项,上下文将无法正确启动,从而导致错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot 测试类可以重用应用程序上下文以加快测试运行速度吗? - Can Spring Boot test classes reuse application context for faster test run? Spring开机单元测试如何加载文件 - Spring boot unit test how to load files 在 JUnit 测试类中使用属性值而不加载整个 Spring 引导应用程序上下文 - Using property values in JUnit test classes without load whole Spring Boot application context Spring boot junit 测试加载应用程序上下文失败 - Spring boot junit test failed loading application context 如何加载,在 Spring 引导测试中,基本 Spring 应用程序上下文仅添加命名组件? - How to Load, in Spring Boot Test, Basic Spring Application-Context Adding Only Named Components? 如何使用 JDBC 在 spring 引导测试类上创建事务上下文? - How to create a transactional context on spring boot test classes using JDBC? 无法在 Spring Boot 测试中加载上下文属性 - Cannot load context properties in a Spring Boot test Spring Boot 应用程序的单元测试用例 - unit Test cases for spring boot application 使用 Camel 的 Spring Boot 无法加载应用程序上下文 - Spring Boot with Camel failed to load application context Spock Framework如何测试Spring Boot应用程序上下文 - Spock Framework how to test spring boot application context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM