Skip to main content
CI/CD X AI

Build an AI Test Generation Bot with GitHub Actions

Automatically generate pytest tests for new code and commit them to your PRs

Build an AI Test Generation Bot with GitHub Actions project preview
GitHub Actions
Gemini API

Difficulty

Mildly spicy

Time to complete

75 minutes

Availability

Free

BUILD

What you'll build

Create a GitHub Actions bot that analyzes new Python code with AST parsing, generates pytest tests via Gemini API, and commits them directly back to your PR branch.

1. Build the AST Code Parser

Create a Python script that extracts function signatures and docstrings using the AST module.

2. Add AI Test Generation

Connect to the Gemini API with prompt engineering that generates meaningful pytest tests.

3. Create the GitHub Actions Workflow

Build a workflow that detects changed Python files and commits generated tests to PR branches.

4. Test with a New Function

Open a PR with a new function and watch the bot generate and commit tests.

5. Add Coverage-Gated Triggers

Only generate tests when coverage drops below 80%, saving API calls and CI time.

Your portfolio builds as you work.

Every project documents itself as you go. Finish the work, and your proof is ready to share.

PROJECT

Real world application

Skills you'll learn

  • AST Code Parsing

    Parse Python source code into abstract syntax trees to extract function signatures

  • AI Test Generation

    Use Gemini API prompt engineering to generate meaningful pytest tests automatically

  • Git Operations in CI

    Configure workflows that commit and push changes directly to PR branches

  • PR-Triggered Automation

    Build GitHub Actions that react to pull request events with path filtering

  • Automated Testing

    Generate real pytest tests that validate function behavior and edge cases

  • Coverage-Gated Triggers

    Only generate tests when coverage drops below threshold to optimize API usage

Tech stack

  • GitHub Actions logo

    GitHub Actions

    CI/CD platform that triggers test generation workflows on every pull request automatically.

  • Gemini API logo

    Gemini API

    Google AI model that analyzes function signatures and generates meaningful pytest test cases.

Watching the bot commit real tests to my PR was a lightbulb moment. It caught an edge case in my factorial function that I would have completely missed. This is how I want every project to work.

Priya Sharma

Software Engineer

OUTCOME

Where this leads.

Relevant Jobs

Roles where these skills matter:

  • DevOps Engineer
  • Platform Engineer
  • Test Automation Engineer
  • Senior Developer

CI/CD x AI

Build production-grade automation pipelines that catch bugs, enforce quality, and deploy safely - the same workflows that power Google and Amazon engineering teams.

FAQs

Everything you need to know

Python's AST module converts source code into a tree structure where each node represents a language element - functions, arguments, docstrings. Unlike regex, which treats code as text and breaks on edge cases, AST understands Python's actual grammar. This is the same approach used by professional tools like pylint, black, and mypy.

Yes. The prompt engineering in this project instructs Gemini to generate tests with real assertions that check function behavior, edge cases (empty inputs, None values, negative numbers), and error handling. You will see this in action when the bot generates tests for a factorial function that verify both correct output and ValueError on negative input.

The workflow uses the [skip ci] tag in commit messages. This tells GitHub Actions to skip triggering workflows for that specific commit, preventing infinite loops where the bot's commit triggers another test generation run. Other workflows like your test runner still execute normally.

Yes, Google AI Studio offers a generous free tier with 1,500 requests per day - more than enough for development and testing. You will not incur any costs completing this NextWork project.

After completing this project, finish the series with Part 4: AI-Powered Stale Code Detector. For more AI-powered DevOps, explore the AWS AI Security Series and the DevOps x AI Series.

One Project. Real Skills.

75 minutes from now, you'll have completed Build an AI Test Generation Bot with GitHub Actions. No prior experience needed. Just step-by-step guidance and a real project for your portfolio.

Mildly spicy level