1

I have been trying to use the matchesJsonSchemaInClasspath method for verifying my API against a predefined JSON, but even if I JSON format, the test case keeps on getting passed, not sure what am I doing wrong here. Or is it the limitation for this.

This is my piece of code.

@Test
public void test(){
    given().get("http://jsonplaceholder.typicode.com/posts/1").then()
            .assertThat().body(matchesJsonSchemaInClasspath("postpaidAccCard.json"))
    .log().all();
}

and the static data I have in "postpaidAccCard.json" is :-

{ "time": "03:53:25 AM", "milliseconds_since_epoch": 1362196405309, "date": "03-02-2013" }

Still the test is passed, will be great if someone can help me out with this.

abhii2628
  • 39
  • 1
  • 7
  • maybe your schema for validation is incorrect. I have gotten false positives because of this in the past. – Andrew Nolan Aug 19 '17 at 16:23
  • @AndrewNolan can you point out, what wrong am I doing. I am have written entire details as to what is happening. – abhii2628 Aug 19 '17 at 17:10
  • Without seeing your json schema to validate against, cant tell if that is the actual issue. – Andrew Nolan Aug 19 '17 at 17:15
  • The JSON was available in the request. Anyway, I have attached it now. { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit" } – abhii2628 Aug 20 '17 at 05:20
  • That's an invalid schema to validate against, which is the issue – Andrew Nolan Aug 20 '17 at 08:35

1 Answers1

1

matchesJsonSchemaInClasspath is a method that compares JSON schema (not plain JSON) with the provided API response (JSON).

For creating JSON schema of an API response:

  1. Go to https://jsonschema.net/home

  2. Paste the API response in the left side window and click on Submit button.

  3. Your JSON schema file will be displayed on the right side window.

  4. Copy and paste the JSON schema in the postpaidAccCard.json file and rerun your test.

dippas
  • 58,591
  • 15
  • 114
  • 126
Navpreet Singh
  • 141
  • 1
  • 5