https://github.com/naugtur/openapi3-tester
Simple customizable testing for APIs defined with OpenAPI v3 spec
https://github.com/naugtur/openapi3-tester
Last synced: 6 months ago
JSON representation
Simple customizable testing for APIs defined with OpenAPI v3 spec
- Host: GitHub
- URL: https://github.com/naugtur/openapi3-tester
- Owner: naugtur
- License: apache-2.0
- Created: 2018-08-23T07:59:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T20:53:43.000Z (almost 3 years ago)
- Last Synced: 2025-03-18T10:53:12.136Z (7 months ago)
- Language: JavaScript
- Size: 250 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# openapi3-tester
Simple customizable testing for APIs defined with OpenAPI v3 spec[](https://www.npmjs.com/package/openapi3-tester)
Leaves choosing what to send and what details to assert to you while automating all validations against the OpenAPI spec.
> Closest thing to automatically-generated test suite that still makes sense long term
## Install
```
npm i --save-dev openapi3-tester
```## Features
- validates input for tests, so tests can't remain outdated when API specification changes
- automatically tests response for the expected status
- allows a human to specify input so failing cases are easier to do than with a test generator
- `reqOptions` is passed to `fetch` (node-fetch package), so there's no limit to the complexity of requests to test
- supports non-standard field `qs` in `reqOptions` because come on, fetch...
- tracks coverge of the API definition## Usage
see `test.js` for an example
```js
const API = apiTester.use(definition)describe('test api', () => {
it('should handle a successful call', () =>
API.test({
path: '/pet/1',
reqOptions: {
headers: { accept: 'application/json' },
qs: {
search: "dog"
},
method: 'get'
},
expectedStatus: 200
}))
it('should handle invalid input', () =>
API.test({
path: '/pet/ohnoerror',
badRequest: true, // skip input validation
reqOptions: {
headers: { accept: 'application/json' },
qs: {},
method: 'get'
},
expectedStatus: 404
}).then(response => {
// optionally assert on response fields
response.body.should.have.property('message')
}))after(()=>{
console.log(API.getCoverageNumbers())
})
})
```### Coverage
API tester has a tiny coverage tracking feature. It's very basic, but should be helpful in tracking which endpoints are missing a test.
`API.getCoverageNumbers()` lists entries from the definition and the number of calls in teests that matched the definition.
Warning: `default` as response code will match all calls to that path and method, even if matching code is defined separately.To get an insight into how coverage was matched to request, call `API.getCoverage()` and see the matchers.