In the last tutorial, we went through the concepts of Rest-assured in theory. To start our practical journey, we need to write code that can send and receive the data with a lot more interesting twists in between. However, the medium that will help us in our API testing is an integrated development environment (IDE). In our case, we will be using the popular Eclipse IDE and in this post, we will prepare it for our coding exercises. In other words, we will configure eclipse with rest-assured for API testing. The index looks as follows:
- What are the prerequisites to configure Eclipse with Rest Assured?
- How to download rest-assured jars in Eclipse?
- Creating a project in Eclipse for rest assured.
- How to setup rest-assured jars in the class path?
What are the prerequisites to configure Eclipse with Rest Assured?
The first step towards setting up the development environment so that we can test some RESTful APIs is to evaluate the prerequisites. The following list highlights the required software for setting up Eclipse with rest-assured. Before proceeding, please make sure they are installed on your system.
- Latest Java version.
- Working Eclipse IDE.
- TestNG setup.
If any of the above is not present on the system, then we have to follow the links given below :
Once the prerequisites are up and running we can proceed with the rest assured set up on Eclipse.
How to download rest-assured jars in Eclipse?
The rest assured jar files can be downloaded from the following link.
When we navigate to this page, we can see the section “Current direct downloads”. Go to this section and click on the link to the dist package.
Note: At the time of this writing Version 4.4.0 is available for download.
Once the link is clicked, the browser will download the rest-assured-4.4.0-dist.zip file on the system (mostly in the “downloads” folder for Windows OS). Navigate to the folder where the zip file was downloaded and simply unzip the files.
Now go to the folder where the files were just unzipped and open it. The contents should be the following in this folder.
- docs: A folder containing javadocs.
- rest-assured-3.0.3.jar: jar file that contains rest-sssured classes.
- rest-assured-3.0.3-deps.zip: Another zip file containing all the dependency jars.
Note: We have to also unzip the rest-assured-4.4.0-deps.zip dependency jars. In the end, your folder would look like this.
Now that we have rest assured jars package ready, we can go ahead and create a project in Eclipse that will use rest assured.
Creating a project in Eclipse for rest assured
To add and use unzipped rest assured jars in an actual project, we have to first create a new project in Eclipse. So we create a project, let’s say, RestAssuredTest as shown below.
Once clicked on the Java Project link, a new project window opens up. Enter the name of the project as RestAussuredTest and click on the Finish button. Once Finish is clicked, we get the following screen. Click Open Perspective. (Alternatively, if we have already checked the option “remember my decision“, then this step will not be seen)
Now the project with the name RestAssuredTest should display in the package explorer.
Once the project is created in Eclipse, now it is required to add the unzipped jars in the classpath of the Eclipse project.
How to setup rest-assured jars in the class path?
Select the Java project folder we just created and right-click on the project folder in the package explorer pane and choose Properties. This will open up the project properties pop-up window as shown below.
Select Java build path option in the left pane of the properties window. In the Java build path pane, on the left-hand side, you will see the Libraries pane.
Here we are going to reference the rest assured jar files that we downloaded earlier. To reference the jars, click on the “Add external jars” button and navigate to the folder where we unzipped all our rest-assured jars. Refer to the image shown below.
Now include the following Jars
- All the jars in the folder rest-assured-3.3.0-deps
With this, we have successfully set up a Java project in Eclipse with a rest-assured library. If we now check the project explorer, we will get the following view.
Now we are ready to use Rest Assured features in Eclipse.
In this article, we configured the Eclipse project with Rest Assured Library.
- Rest Assured library comes in the form of jars which we can download freely from GitHub and unzip on our local machine.
- The prerequisites for using Rest Assured jars are we should have Java, Eclipse, and TestNG properly configured and running on the machine.
- We can then create a Java project in Eclipse and associate the Rest Assured jars with it by specifying the jar path in the Build path.
With these steps, we can configure Rest Assured with the Eclipse project. In the next article, we will create a simple REST API with the Rest Assured library.