Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/khorshedsagor/api-automation-using-mocha-framework

This project is a comprehensive test suite for automating the testing of CRUD (Create, Read, Update, Delete) operations of an API. It utilizes the Mocha framework, Axios HTTP client, and Chai assertion library, with test scripts written in JavaScript.
https://github.com/khorshedsagor/api-automation-using-mocha-framework

api-rest automation-framework axios javascript mocha mocha-chai mochawesome

Last synced: 11 days ago
JSON representation

This project is a comprehensive test suite for automating the testing of CRUD (Create, Read, Update, Delete) operations of an API. It utilizes the Mocha framework, Axios HTTP client, and Chai assertion library, with test scripts written in JavaScript.

Awesome Lists containing this project

README

        

# Comprehensive API CRUD Operations Test Suite using Mocha Framework
![0_gV7fEaDKRGwpprdj](https://github.com/KhorshedSagor/Api-automation-using-mocha-framework/assets/134398536/26187cd4-e6bc-4e82-b03f-94bce72384eb)

This test suite is a comprehensive solution for automating the testing of **CRUD** (Create, Read, Update, Delete) operations of an API. It utilizes the robust Mocha framework, the promise-based HTTP client Axios, and the Chai assertion library. The test scripts are written in JavaScript, providing a familiar and flexible environment for developers.

**Axios** is a renowned HTTP client that simplifies the process of sending requests and receiving responses from the server. Its support for promises makes it an excellent choice for integrating and testing APIs, as it allows for asynchronous operations and better handling of responses.

**Mocha** is a versatile JavaScript test framework that can run on both Node.js and in the browser. It simplifies asynchronous testing by running tests serially, which allows for more flexible and accurate reporting. It also maps uncaught exceptions to the correct test cases, making it easier to identify and fix issues.

**Chai** is a popular assertion library that pairs exceptionally well with Mocha. It allows developers to use natural language constructs when writing tests, making the tests easier to write and read.

**CRUD operations** are the backbone of most data-driven applications. They are essential for manipulating resources in an API, and thus, thorough testing of these operations is crucial for the reliability of the application.

![1_pJRJgw1Vj-1MjhtQFZAZRA](https://github.com/KhorshedSagor/Api-automation-using-mocha-framework/assets/134398536/040bb2ad-3e54-4065-a543-bd72c8022f9b)

## Prerequisites

Before you can run the test suite, ensure that Node.js and npm are installed on your local machine.

## Technology Stack

- **Axios**: A promise-based HTTP client for making requests to the API.
- **JavaScript**: The programming language used to write the test scripts.
- **Visual Studio Code**: The recommended code editor for this project.
- **Mocha Framework**: The testing framework used to structure and run the tests.
- **Mochawesome**: A Mocha reporter that generates a comprehensive HTML/CSS report, providing a visual representation of the test suites.

## API Routes

The test suite covers the following API routes:

- **GET /posts**: Retrieves all posts.
- **GET /posts/1**: Retrieves a specific post.
- **GET /posts/1/comments**: Retrieves comments for a specific post.
- **POST /posts**: Creates a new post.
- **PUT /posts/1**: Updates a specific post.
- **DELETE /posts/1**: Deletes a specific post.

## Setup

1. Clone the repository to your local machine.
2. Navigate to the project directory.
3. Install the dependencies by running the following command:

```
npm install
```

## Running the Tests

To run the test suite, execute the following command:

```
npm test
```

The tests will be executed, and the results will be displayed in the console.

## Test Cases

The test suite includes the following test cases:

- `get all posts`: This test case verifies that all posts can be retrieved successfully from the API.
- `get post by postId`: This test case verifies that a specific post can be retrieved successfully from the API.
- `get comments by postId`: This test case verifies that comments for a specific post can be retrieved successfully from the API.
- `Create a new post`: This test case verifies that a new post can be created successfully in the API.
- `update post by postId`: This test case verifies that a specific post can be updated successfully in the API.
- `delete post by postId`: This test case verifies that a specific post can be deleted successfully from the API.

## Reporting

The test suite generates test reports in the Mochawesome format. You can view the test reports in the console output or in the generated HTML report. Mochawesome provides a full-fledged HTML/CSS report that helps visualize your test suites.

## Test case Report based on Scenerio:
Google Drive Link: https://docs.google.com/spreadsheets/d/1WV09FznyY8iTFiFluwK8N2rTzGlXYi1my230b15V4H4/edit?usp=sharing

## Mochawesome Report:

Screenshot 2023-10-19 at 1 23 00 AM

## Video Output:

https://github.com/Ksagor29/API-automation-using-mocha-framework/assets/83920086/0702683e-a845-4687-b5ab-de50ed5c00d6