137: APIs and Automated Testing with Bas Dijkstra
with Bas Dijkstra
founder
About this episode
Is API testing at the top of your list of things to do this year? Not sure where to start? Or are you currently testing APIs but want to know more about mocking or service virtualization? In this episode Bas Dijkstra, founder of the blog ontestautomation and author of the book Service Virtualization: Implementation, Practices, and Trends for On-Demand Test Environments, shares with us some tips, tools and best practices around API testing.
>Quotes & Insights from this Test Talk with Bas Dijkstra
- In those cases it would be a good idea to at least try and find out if there's an API that exposes that application logic to you, and start writing your automation against that. From my current work there's one example that I've already coded a couple of times which was a … Workshop, based in the US actually, it does sell electronic cigarettes and all kinds of accessories for that. Because I heard they are selling those products in the United States and their selling different kinds of product categories. There are almost 50 different states, each with their own rules and regulations around electronic cigarettes and customers have different ages of course, different dates of birth, then their classified in different age groups.
- If the only part of your test that's featuring the UI is validating whether data is present or data is presented in a given manner or perspective manner, then why waste time and effort writing and running automated tests through user interface just to set up your starting point of your test or the extracted the test preconditions.
- For anybody who knows a little about Selenium web drivers that it's a … I'm not even call it a test tool per say, because it's a browser automation tool that simulates the interaction of a user with a browser. It does not simulate the interaction of a user of a system we make. That should make it pretty clear that Selenium is not a tool for API testing. Well of course, if you have a user interface base or custom framework which is built around Selenium web browser you could easily extend that framework to include API testing, but you need a different tool or library for doing that.
- Also, for those of you watched my session on the Automation Guild, I'm a big fan of using REST-assured for that. Just because it's integrates seamlessly with your any existing automation framework, which written in Java, because it has an easy yet powerful interface or API itself. The actual API of Rest-assured is really powerful, so it helps you to write really powerful, yet really readable and maintainable tests on the API level. So, that would be my first … best suggestion that of course there are also other ways to do exactly the same thing. You can leverage or write something around the HTTP client library yourself, or any other Java or whatever language that you are using. Any kind of library that allows you to search requests and catch validated responses on the API level or the HTP level yourself.
- One possible approach to tackling that problem is using, as you said in the question, mark steps or service fertilization as an approach of simulating the behavior of those dependencies instead of having to deal with managing the dependencies themselves you build simulations using a mocking library or stubs or service virtualization solutions which simulate the behavior of the dependency that you want to use in your tests and integrations and your end to end tests.
- To improve your API test automation efforts is basically a more general tip. Just start exploring your applications and see whether there is anything that you are currently testing at the user interface level which you could also test sufficiently and just as effectively on the API or maybe on the unit test level. So don't think you have to do everything through the user interface, but try and explore, ask around or use a tool like Fiddler to explore your application to see what APIs are available what business logic they expose and how you can leverage those for more efficient test automation in general.
Keep listening
Related episodes

Automation Testing Podcast · Ep. 609
Why Your AI Tests Pass When Your Features Fail with Donovan Brady
with Donovan Brady
Why Your AI Tests Pass When Your Features Fail? Donovan Brady of Leapwork shows how to make
Oct 27

Automation Testing Podcast · Ep. 608
Scary Test Automation POCs Made Easy: Halloween Special With Paul Grossman
with Paul Grossman
Running a proof of concept on test automation tools can feel like a horror movie. Vendors promise
Oct 20

Automation Testing Podcast · Ep. 607
Locust and Azure Load Testing: Create and Debug Load Tests with AI with Lars Holmberg and Abhinav Premsekhar
with Lars Holmberg and Abhinav Premsekhar
Performance testing has never been easier to start, or more important to get right. As teams ship
Oct 6

Automation Testing Podcast · Ep. 606
AI Agents Passed the Tests. Real Devices Didn’t. with Nick Metcalfe
with Nick Metcalfe
Cloud device farms make it easy to get started with real device testing. But what happens when
Sep 29