ApiTestAutomation

API Test Framework

A simple, lightweight API testing framework built with TypeScript, Supertest, and Mochawesome reporting.

Features

Installation

npm install

Usage

Basic Test Structure

import { BaseTest } from '../helpers/BaseTest';
import { AssertionHelpers } from '../utils/AssertionHelpers';

class MyAPITest extends BaseTest {
  constructor() {
    super({
      baseURL: 'https://api.example.com',
      timeout: 5000
    });
  }
}

describe('My API Tests', () => {
  let apiTest: MyAPITest;

  before(() => {
    apiTest = new MyAPITest();
  });

  it('should get data', async () => {
    const response = await apiTest.get('/endpoint');
    AssertionHelpers.expectStatus(response, 200);
  });
});

Available HTTP Methods

Assertion Helpers

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Build the project
npm run build

Environment Configuration

Set the API base URL using environment variables:

export API_BASE_URL=https://your-api.com
npm test

Reports

Test reports are generated in the reports/ directory with both HTML and JSON formats.

Project Structure

src/
├── helpers/
│   └── BaseTest.ts          # Base test class with HTTP methods
├── utils/
│   └── AssertionHelpers.ts  # Assertion utilities
├── tests/
│   └── integration/         # Integration tests
└── index.ts                 # Main exports