Today the process of API testing is the most popular and discussed topic in the field of integration testing. In the next chapters, we will thoroughly analyze the program capabilities of Postman utility which is used exactly as the main component for REST API testing, will thoroughly study some methods of writing such tests on the basis of a real project (which is taken from the net, of course –Yandex. Dictionary).
The Process of Test Planning
Before writing a program code, you should answer some questions: “which methods will be primarily used”, “how exactly the process of testing will be performed”, “what turmoil and difficulties can happen”.
Let’s analyze every detail.
What Methods Will Be Primarily Used?
Answering this question, you should primarily turn to the project’s documentation. In our case, “Yandex. Dictionary” describes only 2 methods (lookup and getLangs) and some parameters for each one.
How Exactly Will the Process of Testing Be Performed?
Primarily, before choosing the most appropriate method of testing, you should thoroughly analyze available parameters for every method of API. Original values of parameters are actually different, it can be a simple number, an object from the list of value or other types of data.
In order to use every similar parameter, you should use your own unique approach: for example, in case if a parameter is a simple number with a valid value (maximum), what will happen after sending a query in a form of a simple number which is much bigger than this value? If our API functions in a proper way, then we’ll get an answer which will show a critical error with this value; a complete absence of error will directly mean that API does not work properly.
For creating a group of tests of original parameters, we can use various test design techniques (for example, equivalency groups, valid values and methods of double tests).
What Turmoil and Difficulties Can Happen?
It means that spending time on creating and checking the tests, you should take a maximum number of possible situations which may happen on the stage of software development into account.
You should quite carefully approach to designing the tests. Imagine that test design is a part of your notorious bug report.
A good code has a well-made structure, is easy to read and optimal.
To make a code always readable, you should use some efficient practices:
- Always try to follow a spacing in the functions blocks, specified criteria and cycles;
- Give variables short and clear names;
- You should not create numerous logical expressions inside modal construction;
- Use typical function, don’t use built-in conditions of programming languages.
To make your code always readable and clear, you should thoroughly improve its structure and consistency. All mentioned algorithms must take a maximum number of steps not having any system errors.
In order to reach a complete best value and complete structure of the software code in the process of writing the tests for API testing, we should talk about 2 methods – input and asserts.
Method of Contained Properties
This method means that every testing which will be performed must be thoroughly described in if else statement. This method is good because if some part of the Postman program does not want to work and check the functionality of your API, the other structures won’t be also checked.
QA specialist completely saves his or her time spent on checking API methods and can immediately understand what is the reason and how to cope with this problem.
A good example of writing a very bad code:
But in order to make this method work in a proper way, a tester must set priorities for the tests, understand the sequence of their execution and also logically think what can break in future and under what conditions.
A good example: a big priority will be assigned to a status code.
If you wanted to see a code 200 but you got another one, you may not continue – just show a status of the error “incoming code is not equal to 200”.
Then you should check if there is any response: if no, then also show the obvious error.
In this case, a bug is that the testers create an associative array with the false value and connected logical testing will get if statement.
In fact, the realization of such method looks like that:
As we know, Assert is a specialized method of calling the program error, complete termination of program’s work: in some cases, some user’s text can be transmitted. In the development field, the assert uses the established algorithm – if there is a system error, you should call a necessary exception with its detailed description.
Automated checking of API testing with the usage of assert method will have the following structure:
Sending a Query from Postman
During a primary installation of Postman, a complete collection of “Postman Echo” becomes available for a user. In simple words, it’s a specialized set of all available queries and responses which are united by a logic.
Postman Echo is specially developed for conducting not complex API testing with previously established settings which can’t be ignored.
In order to perform your first own query, you should do the following:
- Go to “Methods” tab;
- Open “GET queries”;
- Click on the “Send” key.
Your first query was formulated and sent! Everything is very simple and clear.
Queries of POST category is a little difficult but are also clear and logically structured.
This time you should create your personal query. For this, press “+” to open a new page (tab), change the type of query from GET to POST and type the URL needed for your testing.
If you want just to conduct an experiment, you can use a special REST platform “to play” with fake data – https://jsonplaceholder.typicode.com/posts.
Now our task is to formulate a body of POST query. Click on “body” under the input line of a link of the future query, change a format from text to JSON.
The obtained code should be pasted in an editor:
Click on the “Send” key. Soon you will get a personal response with the typed text as a good approval of successful execution of the formed query.
You can save a template of this query for multiple usages in the future.
You can even create a certain collection of such queries.
It’s very easy:
A good peculiarity of Postman is that you can make automated queries by yourself. You only once form a test for your query and every time when you get a response from a server, the program automatically chooses the necessary functionality according to the data in your cases.
Also, we’d like to talk about the Postman environment.
It’s logical that every project has its own virtual environment used for testing and running the developed functionality.
You don’t need to permanently create the queries for every similar environment in Postman application. Supporting numerous queries at the same time is not logical, not practical and can cause numerous discrepancies.
Postman application gives a possibility to develop the user’s environment with any variables which can be easily used in the process of developing the necessary queries and automated tests.
It’s impossible to become a real expert in Postman but it’s very useful, especially comparing its capabilities with a popular version of JMeter for conducting the simplest testing.
Yes, JMeter is in some way simpler and more efficient but it’s very hard to interact with it, especially if you are just a newcomer in this field.
But Postman is a real pleasure in the process of making simple queries for quick testing the functionality of API. We are sure that such a thing can become a comfortable tool for any tester whose task is to perform complete and comprehensive testing of the project.