Just-API, Testing HTTP-based APIs (REST, GraphQL)
In this article I would like to introduce Just-API, An open source framework that I built recently to help people with testing APIs.
What is Just-API?
Just-API is a specification based framework to test REST, GraphQL (or any HTTP-based) APIs. It takes API suite specification from YAML files and runs them either in serial mode or in parallel mode as instructed by the user.
What’s special about Just-API?
It’s declarative, and allows user to test APIs with no code. But a user can always tap into code when they want to.
There are several tools and companies available that offer nice UI to test APIs, but none of them really handle complex API automation flows. Often people go back to programming to test complex flows. So why not a framework that allows users to test complex API scenarios with minimal coding, parallel execution and built-in response validation constructs with some nice reporting.
How does it work?
In simple terms, users build suites by providing request and response validation specification in a YAML suite. Just-API builds the request, makes a call to server and validates response as per the specification. You can choose to validate any or all of
- Response Status code
- Response Headers,
- Response JSON body
- Response JSON schema
A sample REST API test suite
This suite tests
people/1 endpoint of Star Wars service which returns
Luke Skywalker details.
As you can see above, It’s quite simple to write tests.
Here we are checking Response
- Status code is
- Header value of
content-typeheader matches with Regular expression pattern
- JSON body object’s name field’s value is
A sample GraphQL test suite
Following example tests a GraphQL API that returns location for a given ip address.
Sample suite snippets you see here show just the basic stuff we can do with Just-API. It’s packed with tons of useful features.
- Runs test suites in parallel/serial mode
- Supports all widely used HTTP methods
- Supports Form, Multipart requests, File uploads
- Response Validation (Headers, Status code, JSON body, JSON schema, Custom Response Validation function)
- Runs imported custom functions from modules
- Hooks (Before all, After all, Before each, After each, Before test, After test)
- Custom suite configuration
- Chained Request flows
- Ability to define/override Request path, query params, path params, headers, body at runtime
- Storing suite & test data in context for reuse
- Importing specs from multiple suites
- Intrasuite and Intersuite spec dependency execution
- Reusing test specification
- Retry failed tests
- Looping: Generate ’n’ number of tests with a list
- Built-in HTML, JSON reporters
- Ability to generate reports in multiple formats for the same run
- Logging HTTP request/response data for failed tests
- Proper error reporting
- Runs only tests matching with a given pattern/string
- Skipping tests with specification
- Disable or Enable redirections
- Reports test duration
- Allows user to plug-in custom reporters
I really hope you’ll check it out and feel free to leave feedback, request enhancements, or file issues.