chatgpt-create-unit-tests logo

chatgpt-create-unit-tests

Free

GitHub Actions bot that analyses a pull request and adds unit tests if necessary.

FreeFree tier
Inputs: codeOutputs: code
Type
Open Source

About chatgpt-create-unit-tests

chatgpt-create-unit-tests is an open-source GitHub Action that automatically analyzes pull requests and suggests or adds unit tests for new or modified functions. It works by comparing the changes between the pull request branch and the base branch, generating a patch file, and then sending that patch to OpenAI's API (ChatGPT) to request appropriate unit tests. The action then posts the suggested tests as a comment on the pull request. This tool is designed for developers using GitHub who want to streamline the process of ensuring code changes are accompanied by relevant unit tests. It requires an OpenAI API token and appropriate GitHub token permissions to function.

Key Features

Automatically analyzes pull requests for new or modified functions
Generates unit test suggestions using OpenAI's ChatGPT
Posts suggested tests as comments on the pull request
Open-source and free to use (requires own OpenAI API key)
Integrates directly into GitHub Actions workflows
Supports debugging via environment variable

Pros & Cons

Pros
  • Free and open-source, with no subscription costs beyond OpenAI API usage
  • Automates a repetitive task, saving developer time
  • Integrates seamlessly with GitHub Actions
  • Provides test suggestions directly on pull requests for easy review
Cons
  • Requires an OpenAI API key, which incurs usage costs
  • Depends on external API availability and response quality
  • Only analyzes code changes in pull requests, not entire codebases
  • Test suggestions may require manual review and adjustment
  • Limited to languages and frameworks supported by ChatGPT's training data

Best For

Automating unit test generation for pull requests in open-source projectsEnsuring code changes in CI/CD pipelines are accompanied by testsReducing manual effort for developers when adding tests to new functionsImproving code review quality by providing test suggestions automatically

FAQ

How does this action work?
It compares the pull request branch with the base branch, creates a patch of the changes, and sends that patch to OpenAI's API to request unit tests. The suggested tests are then posted as a comment on the pull request.
Do I need an OpenAI API key?
Yes, you must provide an OpenAI API token as a secret named OPENAI_TOKEN in your GitHub repository.
What permissions does the GITHUB_TOKEN need?
The GITHUB_TOKEN needs read and write permissions to allow the action to comment on pull requests. This can be configured in the repository's Actions settings under Workflow permissions.
Can I use this action without commenting on PRs?
Yes, the action will run without the correct permissions, but it will not post comments. The DEBUG environment variable can be set to see more output in the logs.
Is this action free?
The action itself is free and open-source, but you will incur costs from OpenAI for API usage based on their pricing.