Skip to content

ScarRanger/github_test_case_generator

Repository files navigation

GitHub Test Case Generator

A React application that integrates with GitHub to automatically generate test cases for your code files. This tool helps developers create comprehensive test suites by analyzing code files from GitHub repositories and generating framework-specific test cases.

Features

GitHub Integration: Connect to GitHub using personal access tokens ✅ Repository Browser: Browse and select from your GitHub repositories
Smart File Selection: Automatically detect and filter code files by language ✅ Multi-Framework Support: Generate tests for various frameworks:

  • JavaScript/React: Jest + React Testing Library, Cypress E2E
  • Python: pytest, Selenium WebDriver
  • Java: JUnit 5, Mockito
  • C#: NUnit
  • Generic: Template-based tests for other languages

Test Summary Generation: Get AI-powered summaries of potential test cases ✅ Code Generation: Generate complete, ready-to-use test files ✅ Pull Request Creation: Automatically create PRs with generated tests (optional)

Prerequisites

  1. Node.js (v20.19.0 or higher)
  2. GitHub Personal Access Token with repo scope

Installation

  1. Clone the repository:
git clone <repository-url>
cd github_testgen
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev
  1. Open your browser and navigate to http://localhost:5173

Usage

Step 1: Authentication

  1. Enter your GitHub Personal Access Token
  2. Click "Connect to GitHub"

Step 2: Repository Selection

  1. Browse your repositories
  2. Use the search function to find specific repos
  3. Click on a repository to select it

Step 3: File Selection

  1. Review detected code files
  2. Filter by programming language if needed
  3. Select files you want to generate tests for
  4. Click "Generate Tests"

Step 4: Test Generation

  1. Review the suggested test case summaries
  2. Each summary shows:
    • Test framework
    • Test types (unit, integration, E2E)
    • Estimated number of tests
  3. Click "Generate Test Code" for any summary
  4. Review the generated test code
  5. Copy the code or create a Pull Request directly

Step 5: Pull Request Creation (Optional)

  1. After generating test code, click "Create PR"
  2. The app will:
    • Create a new branch
    • Add the test file
    • Create a pull request with detailed description

Supported Test Frameworks

JavaScript/TypeScript/React

  • Jest + React Testing Library: Component testing, props validation, event handling
  • Jest + MSW: API integration testing with mocked services
  • Cypress: End-to-end testing for user workflows

Python

  • pytest: Unit testing with fixtures and parameterized tests
  • Selenium + pytest: Web automation testing

Java

  • JUnit 5: Modern unit testing with annotations and assertions
  • JUnit 5 + Mockito: Integration testing with dependency mocking

C#

  • NUnit: Unit testing framework with test cases and attributes

Generic

  • Template-based test structure for other programming languages

Configuration

GitHub Token Permissions

Required scopes for your GitHub token:

  • repo: Full control of private repositories
  • public_repo: Access to public repositories (if you only work with public repos)

File Type Detection

The application automatically detects these file types:

  • JavaScript: .js, .jsx
  • TypeScript: .ts, .tsx
  • Python: .py
  • Java: .java
  • C++/C: .cpp, .c
  • C#: .cs
  • Go: .go
  • PHP: .php
  • Ruby: .rb
  • Swift: .swift
  • Kotlin: .kt

Development

Project Structure

src/
├── components/           # React components
│   ├── GitHubAuth.jsx   # Authentication component
│   ├── RepositorySelector.jsx
│   ├── FileSelector.jsx
│   └── TestGenerator.jsx
├── services/            # Business logic
│   ├── githubService.js # GitHub API integration
│   └── testCaseGenerator.js # Test generation logic
├── App.jsx             # Main application component
├── main.jsx           # Application entry point
└── index.css          # Global styles with Tailwind

Adding New Test Frameworks

  1. Add framework detection in testCaseGenerator.js
  2. Implement the code generation method
  3. Add framework-specific templates
  4. Update the UI to display the new framework

API Integration

The app uses GitHub's REST API v3:

  • Repository listing
  • File content retrieval
  • Branch creation
  • File creation/updates
  • Pull request creation

Troubleshooting

Common Issues

"Invalid GitHub token"

  • Verify your token has the correct permissions
  • Check that the token hasn't expired
  • Ensure you're using a personal access token, not an OAuth token

"Failed to fetch repositories"

  • Check your internet connection
  • Verify the GitHub API is accessible
  • Try refreshing the token

"Error creating pull request"

  • Ensure you have write permissions to the repository
  • Check that the repository allows pull requests
  • Verify the base branch exists

Rate Limiting

GitHub API has rate limits:

  • Authenticated requests: 5,000 per hour
  • Unauthenticated requests: 60 per hour

The app automatically handles rate limiting with proper error messages.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with React and Vite
  • Styled with Tailwind CSS
  • Icons by Lucide React
  • GitHub API integration via Octokit+ Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the TS template for information on how to integrate TypeScript and typescript-eslint in your project.

Releases

No releases published

Packages

No packages published