Beginner-friendly REST API Testing Guide - Think Like a Programmer
The key to success these days is the ability to respond to changes quickly.
The tester role has been re-defining and evolving because of all the changes, such as Agile, DevOps, product management, envolving architecture such as microservices, etc.
To deliver value faster to the customer, we need the capability to shift our work to production quickly.
Writing automation tests and integrated with a deployment pipeline becoming one of the hottest skills required for the testers today.
The tester role has been re-defining and evolving because of all the changes, such as Agile, DevOps, product management, envolving architecture such as microservices, etc.
To deliver value faster to the customer, we need the capability to shift our work to production quickly.
Writing automation tests and integrated with a deployment pipeline becoming one of the hottest skills required for the testers today.
APIs consumed by many different consumers, and we can't manually test all of them. Automation becomes mandatory.
How we can automate API tests?
How to turn what we've learned so far into lines of codes?
Again, in this tutorial, you'll hear a lot of new words. Remember, be pertinent, be kind to yourself, and keep practice.
Learning how to write a program is like learning to speak a new language. The language that the machine could understand.
You learn through reading books, reading other people's code, and practicing to write code yourself.
This guide is aiming to give you an idea to start.
Let's have a look at Postman again.
In the last tutorial, we talked about Postman is powerful, and you can write tests using it.
Postman tests are written in JavaScript.
Now you see, you already write code without realizing it.
At a certain point, you will need to do some learning to gain the basic concepts of programming.
We won't able to give you a full introduction to the programming languages. We will only cover the concepts we needed in this tutorial, so some extra reading and learning are highly recommended.
Now, the first two basic concepts we introduce here are:
Variables
Variables are used to store information in a computer program. They provide a way of labeling data with a descriptive name.
You can define a variable like this:
String userName = "Today is lovely"
In this piece of code, "String" is the data type, and "userName" is the descriptive name for this variable. And above code give the variable "userName" a value "Today is lovely".
In programming languages, there are different data types.
You can read more about data types:
Again, in this tutorial, you'll hear a lot of new words. Remember, be pertinent, be kind to yourself, and keep practice.
Learning how to write a program is like learning to speak a new language. The language that the machine could understand.
You learn through reading books, reading other people's code, and practicing to write code yourself.
This guide is aiming to give you an idea to start.
Let's have a look at Postman again.
In the last tutorial, we talked about Postman is powerful, and you can write tests using it.
Postman tests are written in JavaScript.
Now you see, you already write code without realizing it.
At a certain point, you will need to do some learning to gain the basic concepts of programming.
We won't able to give you a full introduction to the programming languages. We will only cover the concepts we needed in this tutorial, so some extra reading and learning are highly recommended.
Now, the first two basic concepts we introduce here are:
- Variables
- Strings
Variables
Variables are used to store information in a computer program. They provide a way of labeling data with a descriptive name.
You can define a variable like this:
String userName = "Today is lovely"
In this piece of code, "String" is the data type, and "userName" is the descriptive name for this variable. And above code give the variable "userName" a value "Today is lovely".
In programming languages, there are different data types.
You can read more about data types:
Strings
A string is one of the most commonly used data types. In JavaScript, Groovy, and Java, a string is surrounded by quotes.
Since we're going to use Groovy in the rest of this tutorial, when we explain data types or other coding concepts, it will be in Groovy.
In the example above, we defined a String with the name "userName", and the value as "Today is lovely".
Since we're going to use Groovy in the rest of this tutorial, when we explain data types or other coding concepts, it will be in Groovy.
In the example above, we defined a String with the name "userName", and the value as "Today is lovely".
Further learning
To write proper automation tests, programming is an essential skill that can not be skipped.
You don't need to be an expert in coding, but you do need to understand the terminologies and the basic rules.
We recommend a few programming online courses here, which will help you to get a better idea:
- Java Basic Course from Richard Bradshaw
- Codecademy
- Want to learn Java quickly? Burn all your Java tutorial books
You can go through some of these to further your learning at your own pace.
Few other conceptsNow let's have a look at a few other concepts you also need to know to get your code running and do some testing.
- Compiler
- Gradle
- Git
- Libraries
Compiler
When we write code, we normally using high-level programming languages, such as Java, JavaScript, Groovy, Python, etc. These languages are human-readable language.
When we want to execute the code written by high-level programming languages, we need something to help us translate the human-readable code to executable machine code.
That's why we need a compiler.
You can read more about compiler in here:
Gradle
Gradle is a build tool, which automated the build process.
It can help you manage dependencies, compile source code, package the binary code, run the tests, and publish artifacts.
We will need to use Gradle to build our tests as well.
You can read more about Gradle in here:
Git
Long story short, Git is a version control system that makes it easier to track changes.
If you and your team members are writing automation tests, you will need Git to help the team to track the changes and manage the conflicts.
If you and your team members are writing automation tests, you will need Git to help the team to track the changes and manage the conflicts.
Normally we started by grabbing a remote repository and put what's in it onto your machine.
git clone
This remote repository might include multiple branches, which used to develop different features without impact each other.
The default branch called the "master" branch, which is usually what we deployed on production and used by the customers.
You can switch branches on your machine depends on which features you're working on.
git checkout your-branch-name
Remember, if you make changes, all the changes will be just on your machine, not the remote repository.
After making the changes on your machine, you can check what are they:
git status
git diff
You can also push your changes to the remote repository by using these commands:
git add
git commit
git push
Here is a more detailed explanation of why you need three commands to push to the remote repository.
And you can also learn a bit more about why we need multiple branches, and how to merge them back to "master" branch in here:
If you already have some knowledge about git and want to learn more git commands, you can find a couple of more references here:
LibrariesOne last concept you need to know is libraries.
When we write tests, we only write the code to do the testing.
But we will also need some code to help us manage the tests, run the tests, do the validations, and generate the test reports.
We don't need to write our own code to do all of these, instead, we use libraries.
In the API testing, if you use Java to write the tests, the most commonly used libraries are:
- JUnit
- Rest-Assured
Wrap up
Now, we've learned quite a few new concepts in this tutorial.
You heard a lot of new concepts and will need some time to digest them.
Take your time, and be patient.
If you don't fully understand all of these, it's okay, you will understand a bit more when we move to the next tutorial.
Let's do a quick wrap up.
- You learned the basic programming concepts, such as Variables, String.
- You learned the concepts of the compiler and build tool.
- You learned what is Gradle and why we use it.
- You learned the basic command of Git.
- You learned why we need libraries.
What's next
We included most of the recommended reading in each section.
If you still found some concepts that are not clear, you can google some more.
Few websites are really helpful:
We included most of the recommended reading in each section.
If you still found some concepts that are not clear, you can google some more.
Few websites are really helpful:
- Stackoverflow
- The official website for Gradle and Git.
- Online training website for learning how to program (You can choose the language you like to learn)
Comments
Post a Comment