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

https://github.com/henriquekoaski/codeceptjs-api-tests

End-to-end (E2E) API testing project using JavaScript with CodeceptJS, BDD with Cucumber, and Joi for response validation. Functional tests for the JSONPlaceholder, a free fake and reliable API for testing and prototyping.
https://github.com/henriquekoaski/codeceptjs-api-tests

api-rest bdd codeceptjs cucumber functional-testing gherkin-language javascript joi-validation

Last synced: 4 months ago
JSON representation

End-to-end (E2E) API testing project using JavaScript with CodeceptJS, BDD with Cucumber, and Joi for response validation. Functional tests for the JSONPlaceholder, a free fake and reliable API for testing and prototyping.

Awesome Lists containing this project

README

          

# CodeceptJS-API-Tests

This repository contains automated end-to-end (E2E) API tests for the JSONPlaceholder service, a popular fake online REST API for testing and prototyping.

๐ŸŒ Access the documentation through this link ๐Ÿ‘‰ [JSONPlaceholder](https://jsonplaceholder.typicode.com/)

image

ย 

## ๐Ÿงญ Overview

In this project, I implement automated functional end-to-end (E2E) API tests using **CodeceptJS** with **JavaScript**, following BDD practices with the **Gherkin** language using the **Cucumber** tool. The goal is to ensure the quality and reliability of the JSONPlaceholder API endpoints.

ย 

## ๐Ÿ› ๏ธ Technologies and Tools Used

- JavaScript
- CodeceptJS
- Node.js
- npm
- Cucumber
- Gherkin
- BDD (Behavior-Driven Development)
- Joi (Schema validation)



NodeJS


NPM


Javascript


CodeceptJS


Cucumber


Joi

ย 

## โš™๏ธ Project Structure

This project is designed for **scalability** and **maintainability** for both current and future test scenarios.

- **`features/`**: Contains Gherkin feature files describing the test scenarios in BDD style.
image

ย 

- **`step_definitions/`**: Contains JavaScript step definitions for each feature, organized by domain (e.g., `posts.steps.js`, `users.steps.js`, and `common.steps.js` for shared steps).
image

ย 

- **`data/schema/`**: Contains Joi schemas for validating API responses.
image

ย 

## ๐Ÿงช Automated Test Scenarios

This project covers a variety of positive and negative API scenarios, including:

- **GET all posts**
- **GET post by ID**
- **GET posts by userId**
- **GET all users**
- **CREATE a new user**
- **UPDATE a user**
- **DELETE a user**
- **GET a user that does not exist** (negative scenario, using Scenario Outline for multiple invalid IDs)

All scenarios are written in Gherkin and validated with Joi schemas for contract testing.

ย 

## ๐Ÿ”ฌ Running Tests Locally

### Prerequisites

- [Node.js](https://nodejs.org/en/) (v14+ recommended)
- [npm](https://www.npmjs.com/)
- [Git](https://git-scm.com/)

### Setup

1. **Clone this repository:**
```bash
git clone https://github.com/your-username/codeceptjs-api-tests.git
cd codeceptjs-api-tests
```

2. **Install dependencies:**
```bash
npm install
```

3. **Run the tests:**
```bash
npm test
```

Test results will be displayed in the terminal and logs will be available in the `output/` folder.

ย 

## ๐Ÿ“ Example Test Output

```
Posts --
โˆš GET all posts
โˆš GET posts by id {"id":"1"}
...
Users --
โˆš GET all users
โˆš CREATE a new user
...
โˆš GET a user that does not exist {"userId":"9999"}
โˆš GET a user that does not exist {"userId":"0"}
...
OK | 23 passed // 8s
```