limited time offer

Rest Assured Interview Questions

Showing 1 - 4 of 4 results

What is REST API?

REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services. REST API is a way of accessing the web services in a simple and flexible way without having any processing.

What are the challenges with Rest Assured?

Below is the list of Challenges with Rest Assured:

Language Support: Support only Java Language.

Not Easy to learn: Implementation is not easy. Good Java knowledge required.

Performance Testing: Not integrated with tool.

How to do JSON Schema Validation using Rest Assured?

Use below steps for JSON schema validation using Rest Assured

Step 1: Copy Latest Maven dependency from below link

https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator

Step 2: Get JSON Schema from developer or generate using some tool (Click Here for online Tool) from your api. Use below sample for test (save it with Sample.json):

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "type": "array",
  "items": [
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    },
    {
      "type": "object",
      "properties": {
        "postId": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "postId",
        "id",
        "name",
        "email",
        "body"
      ]
    }
  ]
}

Step 3: Create Sample.java file and paste below code

import org.testng.annotations.Test;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;

import io.restassured.RestAssured;

public class Sample
{
	@Test
	
	public void testJsonSchema()
	{
		RestAssured.given()
			.when()
			.get("https://jsonplaceholder.typicode.com/comments?postId=1")
			.then()
			.assertThat()
			.body(matchesJsonSchemaInClasspath("com/mycompany/api/bl/Sample.json"));
	}
}

Here in get you have to specify your request and in body you have to specify path where your json schema file is.

What is Rest Assured?

REST Assured is a Java library that provides a domain-specific language (DSL) for writing powerful, maintainable tests for RESTful APIs.

It is developed by JayWay Company and it is a really powerful catalyzer for automated testing of REST-services. REST-assured provides a lot of nice features, such as DSL-like syntax, XPath-Validation, Specification Reuse, easy file uploads and with those features we will handle automated API testing much easier.

REST-assured was designed to simplify the testing and validation of REST APIs and is highly influenced by testing techniques used in dynamic languages such as Ruby and Groovy. Rest Assured has a gherkin type syntax. 

Subscribe to Rest Assured Interview Questions