当前位置: 首页 > 知识库问答 >
问题:

重新保证测试hateoas

向安福
2023-03-14

我写的测试用例在RestAs的使用Spring mvc测试Rest的Web服务。

rest响应为

{
  "links": [
{
  "rel": "self",
  "href": "http://www.localhost.com:8080/v1/communities?offset=0&limit=10"
},
{
  "rel": "next",
  "href": "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"
}
  ],
  "content": [
{
.....

我的测试用例是

    when().
        get("/communities").
    then().
        root("links").
        body("href", new ResponseAwareMatcher() {
            public Matcher<? extends Object> matcher(ResponseBody response) {
                return equalTo(new String[] {"http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"});
            }
        });

测试用例错误失败

java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: ["http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]

我甚至试过

equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10");

错误为

java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]

我使用的是Rest Assured 3.0.1。提前感谢您的帮助。

共有1个答案

伯俊弼
2023-03-14

试试这个

assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));
 类似资料:
  • 问题内容: 问题: 当我两次运行相同的go测试时,第二次运行根本没有完成。结果是第一次运行时的缓存结果。 链接 我已经检查过https://golang.org/cmd/go/#hdr- Testing_flags, 但是没有cli标志用于此目的。 题: 是否有可能强制执行测试以始终运行测试而不缓存测试结果。 问题答案: 测试标志docs中描述了一些选项: :使所有测试结果失效 在测试运行中使用不

  • 认证(希腊语: αυθεντικός = 真实的, 从'authentes' = 作者 得来)是一种建立某些东西(或某些人)是可信的行为,也就是做出事物是真实的的声明。认证某个对象可能意味着确认他的出处,认证某个人通常是确认他的身份。认证依赖于一个或多个认证因素。 在计算机安全领域,认证是尝试确认通信发起者的数字身份的过程。一个常见例子是登陆过程。测试认证模式意味着理解认证过程如何产生作用,并使用

  • 问题内容: 我需要针对基于位于以ELB为首的AWS中的Elastic Beanstalk的应用程序进行性能测试。我预计流量约为25 Gbit / s 根据AWS的要求,我正在使用我的AWS组织中的另一个帐户(专用于测试)。该应用程序是我的AWS组织的另一个帐户中的生产应用程序。 我的性能测试将使用生产网站的DNS条目,它将由具有Internet网关的VPC子网中的EC2实例执行。 我对带宽有疑问,

  • 我正在使用放心测试API。我有以下测试,我想用不同的post参数迭代它

  • 我有一个正在添加JLabel的JPanel。然后我想删除所有的JLabel并添加一些新的。 所以我做了以下几点: 这很好。当我在这之后开始一个新线程时,我的问题就出现了,比如: 然后原始JLabels的输出仍然可见。我读到重新验证过程是一个长时间运行的任务,因此firstProducer线程正在启动,而重新验证正在进行并产生冲突。处理这个问题的最佳方法是什么?

  • The most common web application security weakness is the failure to properly validate input coming from the client or from the environment before using it. This weakness leads to almost all of the maj