问题标签 [spring-boot-test]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
spring-boot - 为什么 Spring Boot 测试无法识别属性值?
春季启动+ jdbc模板
我有一个UserDaoTest
,起初我只想测试它而不加载其他组件
执行测试时出现以下错误
但如果更改UserDaoTest
为
没关系。
那么为什么万一它不能spring.datasource.test-while-idle
正确解决以及如何解决呢?
spring - SpringRunner TestRestTemplate 不返回安全标头
我正在使用 TestRestTemplate 的 getForEntity。但是,它不会返回我在 WebSecurityConfig 类中配置的 TLS、HSTS 或 HPKP 标头。然而,它确实适用于现实世界的环境。为什么在测试期间不调用安全过滤器链?
}
spring-boot - Spring Cloud 合约 MockHttpServlet 抛出非法参数异常
我正在使用 Spring Cloud Contract 为使用 eureka 和 Ribbon 的微服务编写测试。我能够生成存根并成功部署它们,但是当我尝试向我的消费者服务发送请求时,它会引发 IllegalArgument 异常。我尝试添加标题,但仍然遇到相同的异常
这是我的代码
这是我得到的例外
mysql - why spring-boot test by H2, but it write data to my local mysql db?
Spring-boot version 1.5.3.RELEASE
;
application-test.yml
file location: ../src/test/resources
and my test BaseClass is:
and now in the test class which extends BaseRestApiTest
, I post data to an URL like http://127.0.0.1:8080/api/user/create
, and finally, the user data was written to my local MySQL DB.
Expecting is the user data was just written in H2
in the memory, but not my local MYSQL DB.
spring-boot - 测试期间不满足的依赖关系
我有一个运行良好的 spring boot 2.0.0 M2 应用程序。
我在构造函数上使用自动装配
当我尝试运行基本测试时
我收到这个错误
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“com.sonos.arcor.service.AddressServiceTest”的bean时出错:通过字段“服务”表示不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.sonos.arcor.service.AddressService”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
我不明白为什么我会收到这个错误。
java - 使用 Spring Cloud Test 测试 Spring Cloud Streams
我已经在我的 Spring Boot 应用程序中定义了一些流生产者(@Output
)和消费者(@Input
),只要我的休息端点。现在我想测试 REST + Streams 使用
首先我想知道这是否可能。对于 REST,我正在自动连接 TestRestTemplate,一切正常:
但是对于我正在尝试使用的流:
这使我能够识别 Rabbit 是否启动,这工作正常,但是当我尝试
并发送消息,我没有收到任何错误,但我的应用程序不会使用这些消息。
我感觉生产者和消费者都是作为我的应用程序的一部分而不是在分离的上下文中启动的,因此这不起作用。
生产者和消费者在不同的应用程序中工作正常,所以这似乎与测试配置有关。
有任何想法吗?是否有人设法在同一个测试中同时测试 REST 和 Streams,@SpringBootTest
因为我找不到任何参考。
我在这里添加一个复制器: https ://github.com/Salaboy/test-spring-cloud-streams/
我将不胜感激您能提供的任何帮助。
spring-boot - spring boot test中如何配置HandlerMethodArgumentResolver
我正在为带有 spting boot 的控制器编写一个单元@WebMvcTest
。
使用@WebMvcTest
,我将能够注入MockMvc
如下所示的对象:-
在控制器中,我Principal
使用 spring 注入一个参数HandlerMethodArgumentResolver
。请告诉我如何使用 编写单元测试MockMvc
,以便我可以Principal
在控制器方法中注入一个模拟对象作为参数。
部分 Auto -configured Spring MVC tests解释了带有注释的测试@WebMvcTest
将扫描HandlerMethodArgumentResolver
. 所以我创建了一个 bean,它扩展HandlerMethodArgumentResolver
并返回模拟Principal
对象,如下所示。
但是参数仍然MockPrincipal
没有传递给控制器方法。
春季启动版本:- 1.4.5.RELEASE
spring-boot - 正则表达式在 Spring-Boot 应用程序的 url 中不起作用
我有以下 URL 的 int 一个资源。
我使用上面的 URL 编写了测试用例。
测试用例 1 和 2 通过。但是对于测试用例 3 和 4,给出“405 Method not allowed”。
tomcat - 与 SpringBootTest 一起使用时,Spring Boot Embedded Tomcat 无法启动
目前,我正在尝试将SpringBootTest与Spring-cloud-contract一起用于集成测试,但由于某种原因,我无法启动并运行 Embedded tomcat 实例。使用 Spring Boot Debug 我得到以下日志
我得到的例外是
测试班
如果您需要更多详细信息,请告诉我。