Home Java Overview Maven Tutorials

Wednesday 31 March 2021

API Testing Interview Questions

API Testing Interview Questions

What are Web Services?

A web Service can be defined by the following ways :-

1). Is a client server application or application component for communication.
2). Method of communication between two devices over network.
3). Is a software system for interoperable machine to machine communication.
4). Is a collection of standards or protocols for exchanging information between two devices of application.

What all challenges are included under API Testing?

API Documentation
Access to DB
Authorizarion Overhead

What is the difference between PUT and POST methods ?

Post :- Creating a new object on the server
Put :- Update the object in server with new table

What are Commonly used HTTP methods?

GET :- It enables you to retrieve data from a server
POST :- It enables you to add data to an existing file or resource in a server
PUT :- It lets you replace an existing file or resource in a server
Delete :- It lets you delete data from a server

List out few Authentication Technique used in API's?

Session/Cookie based Authentication
Basic Authentication
Digest Authentication

What is Rest API?

REST stands for Representational State Transfer. It is set of functions helping developers in performing requests and receive responses. Interaction is made through HTTP protocol in REST API.

What exactly needs to verify in API testing?

In API testing, we send a request to API with the known data and then analysis the response.
1). We will verify the accuracy of the data.
2). Will see the HTTP status code.
3). We will see the response time.
4). Error codes in case API returns any errors.
5). Authorization would be check.
6). Non functional testing such as performance testing, security testing.

What are path parameters and Query parameters for below API Request URL

/ for path parameter
? is for Query parameter
for example

so here /1122369 is path parameter
and ? location is Query parameter also in In General Query Parameter is constructed at the end of URL.

Whar are the core componenets of a HTTP request?

HTTP Request methods like PUT, POST, Delete.
Base Uniform Resource identifier (URI)
Resources and Parameters
Request Header, which carries metadata(a key-value pairs) for the HTTP Request message.
Request Body, which indicates the message content or resource representation.

What could be the HTTP method for below API Scenario? Answer if it is GET or POST.

Scenario :- An API which has Endpoint, Parameter, Headers, cookies and Payload.
Answer :- It is a POST request because it have Payload

What are the differences between API Testing and UI testing?

UI(User Interface) testing means the testing of the graphical user interface. The focus of UI testing is on the look and feel of the application. In user interface testing the main focus is on how user can interact with app elements such as images, fonts, layout etc. are checked.
API testing allows the communication between two software systems. API testing works on backend also known as backend testing.

What protocols is used by the RESTFUL web services?

RESTFUL web services uses the HTTP protocol. They use the HTTP Protocol as a medium of communication between the client and the server.

What are Soap webservices?

SOAP stands for Simple Object Access Protocol. It is an XML based messaging protocol. It helps in exchanging information among computers.

How do we Represent A resource in REST

Using HTTP methods

Can you use POST request instead of PUT to create a resource?

Yes, we can, because POST is Super set of all other HTTP methods except GET.

What do you understand by payload in restful Web Services?

Payload/Body is the secured input data which is sent to API to process the request. Payload is generally represented in JSON format in Rest API's.

What is Rest Assured.

It is Java Library which can automate REST API's.

How would we define API details in Rest Assured Automation?

we shall define all the request details and send it to server in GIVEN, WHEN & THEN methods.

What is Json serialization & Deserialization in Rest Assured.

Serialization in Rest Assured context is a process of converting a Java Object into Request body(payload).

Rest Assured also supports deserialization by converting Response body back to java Object.

List out few common Json Parsing Techniques used in Rest Assured Automation?

Json Path Deserialization of Json using POJO classes.

How would you send attachments to API using Rest Assured Test?

Using MultiPart Method.

Different Status Code & their description :-

200 OK The request was successfully completed

201 Created A new Resources was successfully created.

400 Bad Request The request was invalid

401 unauthorized The request did not include an authentication token or the authentication token was expired

403 forbidden The client did not have permission to access the requested resource

404 Not Found The requested resource was not found

405 Method not allowed The HTTP methods in the request was not supported by the resource.

409 Conflict The request could not be completed due to a conflict.

500 Internal server Error The request was not completed due to an internal error on server side.

503 Service Unavailable The server was unavailable.

Monday 15 March 2021

Reflection In Java

Reflection in java

Java Reflection :- In Java, reflection allows us to inspect and manipulate classes, interfaces, constructors, methods, and fields at run time.

There is a class in Java named Class that keeps all the information about objects and classes at runtime.
The object of Class can be used to perform reflection.

What is the Java Reflection API?
1. Class Manipulator.
2. Used to manipulate classes and everything in a class.
3. can slow down a program because the JVM can't optimize the code.
4. Can't be used with applets.
5. Should be used sparingly.

Reflection of Java Classes

In order to reflect a Java class, we first need to create an object of Class.
And, using the object we can call various methods to get information about methods, fields, and constructors present in a class.

There exists three ways to create objects of Class:
1. Using forName() method
2. Using getClass() method
3. Using .class extension

Example 1:-
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.Class;

class vehicle
public void g()
System.out.println("I am Inside vehicle");
class car extends vehicle
public int x ;
public String name;
System.out.println("i am inside constructor");
car(int x, int y)
System.out.println("Sum is " + (x+y));
public void j()
System.out.println("I am Inside car");
public class TestCsc3
public static void main(String args[]) throws ClassNotFoundException
car cr = new car();
Class cobj = cr.getClass();
TestCsc3 tc = new TestCsc3();
Class cobj2 = tc.getClass();
//get the name of class
String classname = cobj.getName();
System.out.println("Name of the class is " + classname);
//get super class
Class scla = cobj.getSuperclass();
System.out.println("Name of super class is " + scla.getName());
//get the constructor of the class
Constructor[] consname = cobj.getDeclaredConstructors();
for(Constructor c : consname)
System.out.println("Constructor name is :" +c.getName());
//get the modifier of the class
int modi = cobj2.getModifiers();
String modif = Modifier.toString(modi);
System.out.println("Modifier of class is " + (modif));
//get all the methods of the class
Method[] mth = cobj.getMethods();
for(Method m : mth)
System.out.println("Name is the methods" + m.getName());
//get declared methods of the class
Method[] mth2 = cobj.getDeclaredMethods();
for(Method m2 : mth2)
System.out.println("Name is the declared method is :-> " + m2.getName());
//get fields of class
Field[] fld = cobj.getDeclaredFields();
for(Field f : fld)
System.out.println("Name of the fiels is " + f.getName());

Output :-

i am inside constructor
Name of the class is
Name of super class is practice.vehicle
Constructor name is
Constructor name is
Modifier of class is public
Name is the methods j
Name is the methods g
Name is the methodswait
Name is the methodswait
Name is the methodswait
Name is the methodsequals
Name is the methodstoString
Name is the methodshashCode
Name is the methodsgetClass
Name is the methodsnotify
Name is the methodsnotifyAll
Name is the declared method is :-> j
Name of the fiels is x
Name of the fiels is name
Example 2:-

import java.lang.Class;
import java.lang.*;
class pent
public class Reflection2
public static void main(String[] args) throws ClassNotFoundException
Class c = Class.forName("practice.pent");
System.out.println("the name is class " + c.getName());

Output :-
the name is class practice.pent