请放心测试失败java.lang.AssertionError:1个期望失败。 XML路径FixtureId不匹配

时间:2020-08-22 17:55:48

标签: java testng rest-assured

我在测试中遇到错误,已经找到终点,但实际响应为空,但我不知道为什么。我要我的数据提供商向我提供我想要的回复。我得到零。我不知道为什么。我的第二次测试的设备ID不为null。在这种情况下,这是否足够测试?

Json

    [
  {
    "fixtureId": "1",
    "fixtureStatus": {
      "displayed": false,
      "suspended": true
    },
    "footballFullState": {
      "homeTeam": "Dagenham & Redbridge",
      "awayTeam": "Österreich",
      "finished": false,
      "gameTimeInSeconds": 2656,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        },
        {
          "clockTime": 864,
          "confirmed": true,
          "id": 164002,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 60817,
          "teamId": "2"
        },
        {
          "clockTime": 1312,
          "confirmed": true,
          "id": 267245,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 136629,
          "teamId": "1"
        },
        {
          "clockTime": 1760,
          "confirmed": true,
          "id": 758030,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 131840,
          "teamId": "2"
        }
      ],
      "period": "SECOND_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Dagenham-&-Redbridge",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "Österreich",
          "teamId": "AWAY"
        }
      ]
    }
  },
  {
    "fixtureId": "2",
    "fixtureStatus": {
      "displayed": true,
      "suspended": false
    },
    "footballFullState": {
      "homeTeam": "Manchester United",
      "awayTeam": "Leeds United",
      "finished": false,
      "gameTimeInSeconds": 900,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        },
        {
          "clockTime": 864,
          "confirmed": true,
          "id": 164002,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 60817,
          "teamId": "2"
        }
      ],
      "period": "FIRST_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Manchester-United",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "Leeds-United",
          "teamId": "AWAY"
        }
      ]
    }
  },
  {
    "fixtureId": "3",
    "fixtureStatus": {
      "displayed": false,
      "suspended": true
    },
    "footballFullState": {
      "homeTeam": "Garforth FC",
      "awayTeam": "York FC",
      "finished": false,
      "gameTimeInSeconds": 950,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        }
      ],
      "period": "FIRST_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Garforth-FC",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "York-FC",
          "teamId": "AWAY"
        }
      ]
    }
  }
]

端点:

String endpointfixtureId = "http://localhost:3000/fixtures/{fixtureId}";

测试:

public class test extends enablers{

@DataProvider(name = "getData")
public Object[][] getData() {
    return new Object[][]{
            {"1"},
            {"2"},
            {"3"}
    };
}

@Test(dataProvider = "getData")
public void GetUserId(String fixtureId) {
    given().log().all().and().
            pathParam("fixtureId", fixtureId).
            when().
            get(endpointfixtureId).
            then().
            assertThat().
            body(("fixtureId"), equalTo(fixtureId));

}


@Test
public void GetId() {

    given().log().all().
            when().
            get(endpoint).
            then().
            assertThat().
            statusCode(200).
            and().
            body("body", hasSize(numberOfId)).
            and().
            body("fixtureId", notNullValue());


}

}

错误:

    java.lang.AssertionError: 1 expectation failed.
XML path fixtureId doesn't match.
Expected: 2
  Actual: nullErrorCannot GET /fixtures/2

0 个答案:

没有答案