- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
RestTemplate
与其测试版本有什么区别?当我们通过@ControllerAdvice进行异常处理时,RestTemplate会抛出异常,但对于相同的流程测试版本会返回包含异常详细信息的json。
所以,我想看看它们之间的差异摘要。
最佳答案
restTemplate
给你更多的可能性,testRestTemplate
只是restTemplate
的包装,它为你提供了方便的方法,就像你说的,它不不抛出异常,而是用json响应包装它,这样的行为应该在实际应用中由您自己实现,但您在测试中可能不关心。
这是来自testRestTemplate
的javadoc
/**
* Convenient subclass of {@link RestTemplate} that is suitable for integration tests.
* They are fault tolerant, and optionally can carry Basic authentication headers. If
* Apache Http Client 4.3.2 or better is available (recommended) it will be used as the
* client, and by default configured to ignore cookies and redirects.
*
* @author Dave Syer
* @author Phillip Webb
*/
通过ReflectionTestUtils
和ReflectionUtils
可以找到类似的模式
关于Spring TestRestTemplate 与 RestTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271272/
您好,我正在使用 TestRestTemplate 为我的代码实现一些集成测试,在尝试测试端点时我找不到包含查询参数的方法。 这是我尝试过的 2 种不同的测试: @Test @DisplayName(
我有一个 REST (spring-hateoas) 服务器,我想用 JUnit 测试来测试它。因此,我正在使用自动注入(inject)的 TestRestTemplate。 但是我现在如何向这个预配
RestTemplate 与其测试版本有什么区别?当我们通过@ControllerAdvice进行异常处理时,RestTemplate会抛出异常,但对于相同的流程测试版本会返回包含异常详细信息的jso
我有普通的 SpringBoot 应用程序,带有自定义身份验证过滤器,可以正常工作。 但是在集成测试中使用 TestRestTemplate 时遇到问题。 我想在这里检查信用卡错误的用户是否无法登录。
TestRestTemplate 可用于在我们的 Spring Boot 集成测试中发送 http 请求。此类测试通常在 Spring boot 作为随机端口 @LocalServerPort 中的本
我有一个正在使用 kotlin 开发的 spring-boot 应用程序——总体上进展顺利。 ( Spring 1.5.6.RELEASE, Kotlin 1.1.4-3) 无论如何,在查看了一些示例
我有一个在 Tomcat 上运行的 Spring-Boot 应用程序。在其中,我有一个带有请求参数的 RestController。 @RequestMapping(value = "/v1/test
我目前正在使用 Spring Boot 1.5.4 以及 Junit 5 和 Java 8。 我想使用 Junit 的 ParameterizedTest 对存储在 csv 文件中的多个条目设置集成测
我有一个带有 Spring Data Rest 的 Spring Boot 应用程序,我使用 @WebIntegrationTest随着TestRestTemplate在我的集成测试中。测试的基类如下
我有一个 Spring 应用程序的集成测试,它使用 TestRestTemplate 发出请求。每次我发出请求时,模板都会返回一个实体,但 id 始终为空。如果我通过 Postman 执行相同操作,则
我正在学习 Spring Integration 测试并使用 org.springframework.boot.test.web.client.TestRestTemplate。我的 Spring B
//如何将@RequestParam值发送到url enter code here@ApiRestController 公共(public)类 CityController 扩展 BaseContro
我编写了一个 Spring Boot Controller ,用于监听发送到 /orders/ 的 PUT 请求。 在我的集成测试中,我注意到 TestRestTemplate 没有像我预期的那样对
据我所知,MockMvc 只是在测试 Controller,并模拟 Service 层。 同时 RestAssured 和 TestRestTemplate 正在测试我们 API 的运行实例。 这样对
我有一个简单的 Controller ( CODE ) @RestController @RequestMapping("/profiles" , produces = [MediaType.APPL
在我的 springBoot(RELEASE 1.5.20)应用程序中,启用了基本身份验证。我使用以下代码创建了完整的 IT 测试 @RunWith(SpringRunner.class) @Acti
有一个非常轻的 Spring Boot 1.4 项目,生成自 start.spring.io . 尝试使用 TestRestTemplate 为 @RestController 与 @RequestB
我知道这里已经出现过几次类似的问题,但遵循建议的修复方法并没有解决我的问题。 我有一个带有以下端点的简单 Controller : @RequestMapping(method = RequestMe
我正在使用 TestRestTemplate 对我们的产品进行集成测试。 我有一个看起来像这样的测试: @Test public void testDeviceQuery() { Respon
我有一个资源 A,它有一个 Controller ,其中包含一个用于检索分页 A 项目的端点: public ResponseEntity getAllAs( @Pageabl
我是一名优秀的程序员,十分优秀!