Skip to main content

ApiTest CI

API Test Framework

Table of Contents

Prerequisites

Installation

Install Node.js and pnpm

Ensure you have Node.js and pnpm installed. You can download them from the following links:

Install Node Modules

To install the required node modules, run:

pnpm install

Run Tests

  • npm test to run all test

Generate HTML Reports using jest-html-reporters

To generate HTML reports for your tests, you can use jest-html-reporters. The configuration is already set up in jest.config.ts.

Making HTTP Requests using axios

This project uses axios for making HTTP requests. You can find the helper functions for making GET, POST, PATCH, and DELETE requests in src/helper/apiHelper.ts.

Generating Fake Data using faker

This project uses faker for generating fake data. You can find an example of how to use faker in src/helper/create.ts.

Additional Jest Matchers using jest-extended

This project uses jest-extended for additional Jest matchers. The configuration is already set up in jest.config.ts.

Usage

const { HttpGet, HttpPost, HttpPatch, HttpDelete } = require('../helper/apiHelper');
const { baseUrl, getEndpoint } = require('../config/config');

Example

const { HttpGet, HttpPost, HttpPatch, HttpDelete } = require('../helper/apiHelper');
const { baseUrl, getEndpoint } = require('../config/config');

describe('API Testing Framework', () => {
test('should get all posts', async () => {
const endpoint = getEndpoint('getPosts');
const response = await HttpGet(`${baseUrl}${endpoint?.path}`);

expect(response.status).toEqual(200);
expect(response.data).toBeInstanceOf(Array);
});
});

Built With

DependencyUse
AxiosPromise based HTTP client for the browser and node.js
Fakergenerate massive amounts of fake data
uuidSimple, fast generation of RFC4122 UUIDS.
npm-run-allA CLI tool to run multiple npm-scripts in parallel or sequential.
lodashodash makes JavaScript easier working with arrays,
rimrafThe UNIX command rm -rf for node
cross-envRun scripts that use environment variables across platforms

Results