API Functional Testing – The Black-Box approach

I’m a big fan of the BAT Series from John Sonmez (SimpleProgrammer), a good start for testers doing Web automation. These series of articles show you a clear and simple way to start creating your web automation framework with tools like Selenium.

The BAT stands for “Blackbox Automated Tests” so I thought it would be also useful to use the same approach for other levels of functional testing (not only Web automation).

Datahug API is the product we use at work to integrate relationship intelligence with other CRM platforms like Salesforce.com or SugarCRM, so it’s a very important pillar of our SaaS business.

We’ve used SoapUI (Free version) in the past for API functional testing, it was useful at the start because it did not require (almost) any coding skill to use it. But after some months, it became a nightmare in terms of maintainability and test results reporting. It was just too hard to re-factor tests and troubleshoot issues. (SoapUI Pro version might had solved some of the pain but we did not considered buying a new tool)

We just decided to switch to a “BAT like” solution as we already had experience with our Web automation framework. It involves coding a new framework but it keeps things really easy for testers when writing tests, so we can focus on testing the actual functionality and not on how the API is implemented (Black box!).

Here you have a code example on how our web functional tests looks like:

pascual4

As you see, it is really easy to write functional tests for Testers without advanced programming skills. When building our API automation framework we decided to use RestSharp as the HTTP client for handling the API calls. RestSharp is a simple REST and HTTP API Client for .NET that simplifies dealing with HTTP requests (and it’s Open♥Source!). Here you have an example on how to use it (from the library’s official site):

pascual 3

We’ve wrapped all RestSharp code in our ApiClient class that handles the API requests/responses so then we can easily write tests in a similar way as we do in our Web automation framework (see that we try to keep the functional tests really simple and we enforce the “Triple A” rule):

Code

 Below you can see the actual implementation of the methods that we use to Act and Assert on the previous test (notice how simple and maintainable is to build the API call with RestSharp):

 

Code

 With this approach, we are building an API functional test suite that is integrated in our Continuous Integration pipeline and allows us to get quick feedback and catch bugs early on our API. We can also decide the level of logging we need for troubleshooting issues and we’re not tight to any commercial tool.

Looking forward to your comments and… Happy Testing!

 

About the Author:

VictorPascual

Born in Barcelona, Victor started his career in Software Testing working with medical desktop applications on a highly regulated environment, then moved to Ireland and started working on a fast growing SaaS company in the Relationship Intelligence space, leading team on testing Web and Mobile applications. He has a passion for Agile Testing, Test Automation and Software Craftsmanship.

Victor works for Datahug as a Test Lead in the Engineering Team.

Victor likes being involved in the testing community and can be contacted on LinkedIn,Twitter and on his Testing Island blog site.

About the Author

Victor

Find out more about @victor-pascual-villanueva

Related Content