Getting Started With Jenkins and API Testing
Integrating ReadyAPI with Jenkins
If you were to ask a room full of crowded people, “who is the most popular butler in the world?” - you’d probably get a few different answers. Maybe Albert, from Batman, Lurch from Adam's Family, or even Jeffrey, from Fresh Prince of Bel-Air. Ask that same question and you are likely to get only one answer: Jenkins.
Jenkins is the butler of modern software, a framework for executing tasks during a delivery pipeline, and the most popular infrastructure for teams that have adopted continuous integration. Tell it to go grab a GitHub repo and build it, or send a message when a task is complete and it will do it with robotic efficiency. Which makes it perfect for automating test cases in a continuous integration process. In this tutorial, we'll look at how Jenkins and ReadyAPI integrate and make testing APIs in continuous fashion a breeze.
What Is Continuous Integration?
Continuous integration is simply the act of committing small changes of code to a master branch frequently. It helps avoid the monster merge - when different developers merge large pieces of code into the main repository, often causing bugs and defects. By quickly integrating small chunks of code we can be sure that we don’t break older code with our changes. And when things do break (they will!) you’ll be able to track down the reason quickly - as you’ll have only added a few lines of code instead of a few thousand!
Where Jenkins Fits In
While “integrating” may seem easy, there are actually many tasks, sometimes hundreds, that need to happen in order for the integration to be successful. Jenkins is an open sourced CI server that orchestrates many of these tasks: packaging the application and dependencies, building the application, running unit tests, e2e tests, API tests, and more.
Jenkins used to actually be called Hudson, and was conceived inside the walls of Sun before growing in the open source community. When Oracle bought Sun, the community and new owners fought for ownership of the Hudson project. Oracle retained the propriety rights to the original project, and the community focused heir efforts on a Hudson fork, called Jenkins. Fast forward a few years and Jenkins is now one of the most popular pieces of software in the world, and Hudson is right next to the Microsoft Zune.
One of the main advantages to using a CI server is that it gives software teams a central place where they can execute and report on everything happening in their pipeline. In today’s tutorial we’ll be showing you how to run your API tests using ReadyAPI right inside your pipeline or in a new project.
Jenkins is supported by Windows, Mac, and Linux operating systems, though this tutorial will be shown using HomeBrew to help us install Jenkins on Mac.
If you don’t have brew installed, what are you waiting for? Seriously, it’s an awesome package installer for Macs that can be found here: https://brew.sh/
You can also open up a terminal window and paste this line in:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once brew is done setting up and fully installed, just open up a terminal and enter:
~ brew install jenkins
Jenkins should now start installing on your machine. Once it’s installed, you’ll need to start it up on your machine. In there terminal, enter:
Jenkins uses port :8080 to display a web interface, so check http://localhost:8080 to see if it finished starting up.
Setting Up Jenkins and Adding ReadyAPI
Jenkins will ask us a few questions, like if we want to install their recommended list of plugins. You can if you’d like, though I will state that I think their list is too long. Having both Git and SVN seems redundant to me, but I digress.
Once we are through our installation, you should see the Jenkins home screen, which looks like this:
Now we’ll add the ReadyAPI Jenkins Plugin. On the left hand menu, select Manage Jenkins. Then select Plugin Manager. On the tab menu, select “Available”. You should see a long list of available plugins for Jira. Ou can filter for SoapUI Pro, then select it. Click Install Without Restart.
Creating A Freestyle Project
Great, now that we’ve got everything installed and running, let’s create our first project, by selecting New Item in the left hand menu.
Once on the Projects screen, we have a few different options to select from like Freestyle, Pipeline, Multi-branch and more. For this tutorial, we’ll choose a Freestyle Project.
Click Save and you’ll be presented with the Project Settings page. It’s here where we’ll describe our project and add build-steps or tasks. You can also integrate a Source Code Management tool, like Git, to track and store the code you’ll be using for tests and your application.
Adding ReadyAPI To Jenkins
You can add ReadyAPI tests to Jenkins in two different ways, via a command line execution script or our native Jenkins plugin you can find at the Jenkins plugin store.
To add ReadyAPI to our Jenkins build, we’ll scroll down to the Build section, click Add build step, and then select “Execute shell”.
Alright, now we’ll need to go into ReadyAPI, so go ahead and open it up. If you don’t have a license you can grab a free trial here: https://smartbear.com/product/ready-api/soapui/free-trial/
In the menu on the left, right-click the test case you’d like to automate. In the right-click menu, you should see Launch Test Runner - click it and you'll see the TestRunner menu.
Here, you can fill in particular settings of your test run, like reporting style or project passwords. You don't need to enter anything in here, so we can go ahead and hit Get Command Line. This will bring up a string of text with project and runner file location and a few other snippets.
You can copy this text to your clipboard, or click the Copy to Clipboard button. Now we'll head back to Jenkins and paste this in as our build step!
Once pasted, click Save on the bottom left. We're all set - now we can build our project and see the results!
You can head back to the Projects page and click Build!
Once built, select Console Output to see Jenkins go to work, run those tests, and get reports!
If you haven’t done so, you’ll need to download the SoapUI Pro Jenkins plugin from the plugin store to continue: https://plugins.jenkins.io/soapui-pro-functional-testing
Just like in the command line step, let’s open up the Add build step in the Build section. Instead of selecting “Execute shell”, find and select “SoapUI Pro: Run Functional Test”.
Jenkins will now give you a menu for the SoapUI Pro plugin, so let's start filling in the information we need.
Head back into ReadyAPI, and we'll need to grab two file paths.
My example looks like this:
Path to testrunner:
Path to SoapUI Pro project:
We'll leave the other options blank for now, as these first two fields are required.
Jenkins now knows where our TestRunner file is and our Project file, so we are all set to Save at this point.
Now, back on the Project Dashboard, you can click Build Now to start the project!
Now you should be able to navigate Jenkins and ReadyAPI, and integrate them together - taking your API testing to the next level. Continuously integrating API and other automated tests is one of the simplest ways to provide maximum quality to end users while also ensuring your able to bring new features to market quickly.