Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
This blog will help you to implement the BDD style API testing in REST Assured. We will learn the keywords and dependencies required to implement the API testing in REST Assured using the BDD structure and discuss what BDD is.
But before we jump into that, let's know about REST Assured first.
REST Assured
A REST Assured is an API testing tool that was developed by Johan Haleby. REST Assured is a Java package we can install in our java project to implement the API testing, validate the response we are getting, and make changes according to the response. REST Assured is also an open-source program implemented in the Groovy programming language.
REST Assured supports all the HTTP methods like PUT, POST, GET, DELETE, and UPDATE. You can also use the headers, cookies, and parameters to validate the response of the HTTP request.
You can check out the following blog to learn more about REST Assured.
BDD stands for Behaviour Driven Development, and it is one of the testing methods to test the application's working and to check if it is working according to the owner's expectation. One of the advantages of using the BDD style testing is that the test cases are written in a language readable by everyone included in the application development.
BDD removes the barrier between the technical and non-technical teams, helps them to understand the application's working, and makes changes depending on the user's behavior when using the application.
BDD helps to make the developers, stakeholders, and other team members discuss the application behavior depending on the test cases in a common language.
You need to know the following given annotations when writing the test cases in BDD.
Given: using given() keyword, we need to define scenarios, or we can say we need to set header information, params, auth, and cookies.
When: when() keyword tells which statement to execute.
Then: then() keyword tells the response of the previous statement that was executed.
For better understanding, we will implement all these annotations in our code.
Implementation of BDD in REST Assured
Create a Maven project
Let's make a maven project in IDE. We will be using Eclipse IDE for the implementation, but you can use IntelliJ or any other java based IDE; that's up to you.
First, go to file < project < maven project and then create a maven project by filling in all the necessary information.
You need to write the name for your maven project in the group id and artifact id.
Before we discuss the implementation of the BDD style in REST Assured, you need to ensure you have the necessary dependencies in your pom.xml file. You must add the dependencies in the <dependencies/> tag, and each package will have a separate <dependecy/> tag like the one given below.
You can see in the above code that we are implementing all the keywords given, then, and when in the function named getrequest(). Remember that you need to start your code with given() keyword used. To access further keywords. Include these header files in the code to implement BDD annotations in REST Assured.
In the above code, we are giving a GET request to the public API https://ghibliapi.herokuapp.com/films, and if the request is successful, we will get the status code 200 in return.
You can see in the console our test for the GET request has been passed.
You can perform multiple requests in REST Assured in BDD style. This was one example of implementing the GET request in REST Assured in BDD style.
Frequently Asked Questions
Is REST Assured a java library or framework?
REST Assured is a java based library to test the APIs.
Can we test the SOAP APIs in REST Assured?
We can, but REST Assured does not explicitly support SOAP APIs testing.
What makes the REST Assured code human-readable?
BDD style testing makes the REST Assured code human-readable.
Does REST Assured support only JSON data format?
No, REST Assured supports both XML and JSON data formats.
Do we need to buy the license for REST Assured?
REST Assured is an open-source API testing tool, so you do not need to worry about the license.
Conclusion
This blog taught us about the BDD style testing in REST Assured. We discussed what BDD is in general, and we also learned how to create a maven project and implement a GET request in REST Assured using the BDD style.
To learn more about REST Assured, you can check the following articles.