⬡ Hub
Skip to content

API-Test-Project

API Testing Project

This project demonstrates sample API applications in Java and Python, along with API testing frameworks using industry-standard tools.

Project Structure

Gemini-API-Test-Project/
|-- java-api/                         # Contains the sample Java Spring Boot API application
|   |-- src/
|   |   |-- main/
|   |   |   `-- java/com/example/demo/
|   |   |       |-- controller/HelloController.java
|   |   |       `-- DemoApplication.java
|   |   `-- test/
|   `-- pom.xml
|-- python-api/                       # Contains the sample Python Flask API application
|   |-- app.py
|   `-- requirements.txt
|-- api-testing-frameworks/
|   |-- java-rest-assured/            # API testing framework for Java and Python APIs using RestAssured
|   |   |-- src/
|   |   |   `-- test/java/com/example/apitests/ApiTests.java
|   |   `-- pom.xml
|   `-- python-pytest-requests/       # API testing framework for Java and Python APIs using Pytest and Requests
|       |-- tests/test_api.py
|       `-- requirements.txt
`-- README.md

How to Run the Applications

1. Java API (Spring Boot)

This API will run on http://localhost:8080.

  1. Navigate to the java-api directory: bash cd Gemini-API-Test-Project/java-api
  2. Build the application using Maven: bash mvn clean install
  3. Run the application: bash mvn spring-boot:run The API will be accessible at http://localhost:8080/hello.

2. Python API (Flask)

This API will run on http://localhost:5000.

  1. Navigate to the python-api directory: bash cd Gemini-API-Test-Project/python-api
  2. (Optional) Create and activate a virtual environment: bash python -m venv venv .\venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux
  3. Install the dependencies: bash pip install -r requirements.txt
  4. Run the application: bash python app.py The API will be accessible at http://localhost:5000/hello.

How to Run the API Tests

Before running the tests, ensure both the Java API and Python API applications are running.

1. Java API Tests (RestAssured)

  1. Navigate to the java-rest-assured directory: bash cd Gemini-API-Test-Project/api-testing-frameworks/java-rest-assured
  2. Run the tests using Maven: bash mvn test This will execute the tests defined in ApiTests.java.

2. Python API Tests (Pytest with Requests)

  1. Navigate to the python-pytest-requests directory: bash cd Gemini-API-Test-Project/api-testing-frameworks/python-pytest-requests
  2. (Optional) Create and activate a virtual environment (if not already done for the Python API): bash python -m venv venv .\venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux
  3. Install the dependencies: bash pip install -r requirements.txt
  4. Run the tests using Pytest: bash pytest This will execute the tests defined in test_api.py.

A Note on Selenium WebDriver for API Testing

You initially mentioned using Selenium WebDriver for API testing. It's important to clarify that Selenium WebDriver is primarily designed for automating web browsers and testing user interfaces (UI). It simulates user interactions with a web page (like clicking buttons, filling forms, navigating pages).

API testing, on the other hand, involves directly interacting with the application's backend endpoints without a graphical user interface. This typically means sending HTTP requests (GET, POST, PUT, DELETE, etc.) and validating the responses.

While it's technically possible to use Selenium to interact with a web application that then makes API calls, it's an indirect and inefficient way to test the APIs themselves. It adds unnecessary overhead (browser startup, rendering) and doesn't allow for direct validation of API contracts, performance, or error handling at the API level.

For robust and efficient API testing, tools like RestAssured (for Java) and Requests with Pytest (for Python) are the industry standard. They allow for direct HTTP communication, easy assertion of response data, and are much faster and more reliable for this purpose than a UI automation tool like Selenium.

Files and Subdirectories