Skip to content

Files

196 lines (129 loc) · 6.12 KB

README.md

File metadata and controls

196 lines (129 loc) · 6.12 KB

Trafix - API Testing Framework

Trafix is a modern, efficient API testing framework that simplifies the process of generating, executing, and managing API test cases. Built with a Go backend and Next.js frontend, Trafix delivers high performance, reliability, and an intuitive user experience.


🚀 Features

  • Dynamic Test Case Generation: Automatically create test cases based on provided API details.
  • Interactive Frontend: A clean and responsive interface for managing test cases and viewing results.
  • Test Case Customization: Edit, delete, or add new test cases seamlessly.
  • Execution and Results Display: Execute test cases and review structured results, including status codes, response bodies, and execution times.

📋 Table of Contents

  1. Frontend Workflow
  2. Backend Workflow
  3. Backend Test Case Generation
  4. Usage
  5. License
  6. Future-Enhancements
  7. Contributing

🔄 Frontend Workflow

1. User Interaction

  1. API Information Form:

    • Input fields for:
      • Endpoint URL
      • HTTP Method (GET, POST, PUT, DELETE)
      • Headers (optional)
      • Payload/Body (for POST/PUT requests)
  2. Generated Test Cases Display:

    • View autogenerated test cases, such as boundary tests and response validation tests.
  3. Edit Test Cases:

    • Modify, delete, or add new test cases.
  4. Execute Test Cases:

    • Click a button to execute all test cases.
  5. View Results:

    • Results displayed in a table format with:
      • Test case name
      • Status code
      • Response body
      • Execution time

🔧 Backend Workflow

1. Test Case Management

  • Receiving API Info: API details are received from the frontend via the Go backend.
  • Generating Test Cases:
    • Predefined logic or AI APIs (e.g., OpenAI) create diverse test cases.
    • Test cases are stored in a MongoDB database.

2. Test Case Execution

  • Execution Trigger: A Kestra workflow is initiated with test case details.
  • Execution and Storage:
    • Test cases are executed, and results are stored in MongoDB.
    • Results include response details like status codes and execution times.

3. Alternate execution

  • Manual Execution: Test cases can be executed manually via the backend API.
    • Endpoint: /api/test-cases/run
    • Input: Test case details
    • Uses Go routines for parallel execution.
  • Customization: Users can customize test cases or add new ones as needed.

📂 Backend Test Case Generation

  1. Receive API Info:

    • Endpoint: /api/generate-test-cases
    • Input: API details (URL, method, headers, payload)
    • Validation: Ensure required fields are provided.
  2. Generate Test Cases:

    • Happy Path Tests: Valid inputs expected to succeed.
    • Negative Tests: Invalid inputs (e.g., wrong data types, missing fields).
    • Boundary Tests: Edge cases for parameters.
    • Performance Tests: High payload or frequent requests.
  3. Store Test Cases:

    • Save test cases in the test_cases collection in MongoDB.
  4. Execute Test Cases:

    • Endpoint: /api/test-cases/run
    • Trigger Kestra workflows for test execution.
  5. View Results:

    • Display test results with details like status codes and execution times.
    • Data stored in the test_results collection in MongoDB can be viewed in the frontend.

📦 Usage

After setting up the backend and frontend, you can start using Trafix to test APIs. Follow these steps to get started with the development environment:

  1. Clone the Repository:

    git clone https://github.com/kyrexis/trafix.git
  2. Add environment variables:

    • Create a .env file in the frontend and backend directory, following the env.example file.
  3. Install Dependencies:

    • Install dependencies for the frontend and backend:

      cd frontend
      npm install
      cd ../backend
      go mod tidy
  4. Run the Application:

    • Start the frontend and backend servers:

      cd frontend
      npm run dev
      cd ../backend
      air
    • The frontend will be available at http://localhost:3000, and the backend will run on http://localhost:5000.

    • Install Air using go install github.com/air-verse/air@latest if you don't have it installed.

    • Start redis server using redis-server if you don't have it running or use Docker.

      docker run -dp 6379:6379 redis

📄 License

Trafix is licensed under the MIT License.


🎯 Future Enhancements

We have exciting plans to further improve Trafix and provide a more comprehensive API testing experience:

  1. Enhanced Reporting: Add more detailed analytics and insights for test case execution, such as visualized metrics and trends.
  2. Multiple Test Formats: Provide support for importing and exporting test cases in popular formats like Postman collections and Swagger files.
  3. Integration Testing: Extend the framework to include support for integration testing, enabling end-to-end validations.
  4. CI/CD Integration: Seamlessly integrate Trafix with CI/CD pipelines using tools like Jenkins, GitHub Actions, GitLab CI, and others.

🤝 Contributing

Trafix is Open Source 🥳🥳

Feel free to reach out to us if you have any questions or ideas. We welcome contributions to Trafix! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes and commit them (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Open a pull request to the main branch.

Please make sure your code follows the existing style and includes proper tests where applicable.

We encourage contributions from the community. Whether it's fixing a bug, adding a new feature, or improving documentation, your input is valuable. For any questions or feedback, feel free to open an issue or reach out to us.