Skip to content

jasonxu08/githubUTGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Unit Test Generator

A Chrome extension that adds a "Generate Unit Test" button to GitHub file pages, allowing you to automatically generate unit tests for selected functions using GitHub Copilot or AI APIs.

✨ New: GitHub Copilot Integration

No API key configuration needed! The extension now integrates directly with GitHub Copilot, using your existing subscription to generate unit tests.

Features

  • 🤖 GitHub Copilot Integration: Uses your existing GitHub Copilot subscription (no extra API keys needed)
  • 🔍 Smart Function Detection: Automatically detects if selected code is a function
  • 🎯 Context-Aware: Analyzes surrounding code for better test generation
  • 📁 Smart Path Generation: Suggests appropriate test file paths based on project structure
  • 🌐 Multi-Language Support: Supports JavaScript, TypeScript, Python, Java, C#, Go, PHP, Ruby, Rust, and more
  • GitHub Integration: Seamlessly integrates with GitHub's UI
  • 🔄 Multiple Modes: Copilot chat, editor integration, or template generation

Installation

  1. Clone or download this repository
  2. Open Chrome and navigate to chrome://extensions/
  3. Enable "Developer mode" in the top right
  4. Click "Load unpacked" and select the extension directory
  5. Start using with GitHub Copilot (no configuration needed!)

Usage (GitHub Copilot Mode)

  1. Navigate to any file on GitHub
  2. Select a function or code block you want to test
  3. Click the "Generate Unit Test" button that appears
  4. The extension will automatically:
    • Open GitHub Copilot chat, OR
    • Insert test generation prompts in the editor, OR
    • Show a template dialog with guidance

No API key configuration required - uses your existing GitHub Copilot subscription!

Alternative: External AI APIs

If you prefer to use external AI services, you can still configure API keys:

  1. Click the extension icon in the Chrome toolbar
  2. Select your preferred AI provider (OpenAI or Anthropic)
  3. Choose the model you want to use
  4. Enter your API key
  5. Click "Save Configuration"

API Keys

Supported Languages

The extension automatically detects the programming language and generates appropriate tests using the recommended testing framework:

  • JavaScript/TypeScript: Jest
  • Python: pytest
  • Java: JUnit 5
  • C#: xUnit
  • Go: Go testing
  • PHP: PHPUnit
  • Ruby: RSpec
  • Rust: Rust test framework

Test Generation Approaches

🚀 Copilot Chat Integration

  • Automatically opens GitHub Copilot chat
  • Sends structured test generation prompts
  • Provides complete test code with proper setup

✏️ Editor Code Generation

  • Inserts test generation comments in GitHub's editor
  • Uses Copilot's code completion for test generation
  • Perfect for in-browser editing workflow

📋 Template Dialog

  • Provides suggested test file paths
  • Generates language-specific test templates
  • Includes step-by-step instructions for manual setup

Test Generation Features

The generated tests typically include:

  • ✅ Happy path scenarios
  • ✅ Edge cases and boundary conditions
  • ✅ Error handling tests
  • ✅ Proper mocking of dependencies
  • ✅ Descriptive test names and comments
  • ✅ Language-specific best practices

Privacy & Security

GitHub Copilot Mode

  • Uses your existing GitHub authentication
  • No additional data storage required
  • All interactions through GitHub's official Copilot interface

External API Mode

  • API keys are stored locally in Chrome's storage
  • No data is sent to our servers
  • All communication is directly between your browser and the chosen AI service
  • Selected code is only sent to the AI service you configure

Quick Start Guide

  1. Install the extension (see Installation section above)
  2. Go to any GitHub repository file
  3. Select a function - make sure to select the complete function code
  4. Click "Generate Unit Test" - button appears automatically
  5. Let Copilot generate your tests - no setup required!

For detailed usage instructions, see USER_GUIDE.md

Development

File Structure

├── manifest.json          # Extension manifest
├── content.js             # Main content script for GitHub integration
├── background.js          # Background script for AI API calls
├── popup.html            # Extension popup UI
├── popup.js              # Popup functionality
├── styles.css            # Styling for modals and buttons
├── icons/                # Extension icons
└── README.md             # This file

Building

No build process required. This is a vanilla JavaScript extension that works directly in Chrome.

Testing

  1. Load the extension in developer mode
  2. Navigate to any GitHub repository file
  3. Select some function code
  4. Test the generation functionality

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

MIT License - see LICENSE file for details

Roadmap

  • GitHub Copilot integration
  • Support for more AI providers
  • Batch test generation for entire files
  • Integration with GitHub's create file API
  • Support for more programming languages
  • Custom test templates
  • Test coverage analysis
  • GitHub Enterprise support

Troubleshooting

Button doesn't appear

  • Make sure you're on a GitHub file page (not directory listing)
  • Check that the extension is enabled
  • Refresh the page

API errors

  • Verify your API key is correct
  • Check your API quota/billing
  • Ensure you have the right permissions for the selected model

Generated tests are poor quality

  • Try selecting more context around the function
  • Use a more powerful model (GPT-4 vs GPT-3.5)
  • Ensure the selected code is actually a complete function

Support

If you encounter issues or have suggestions, please open an issue on GitHub.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published