AI DevelopmentJan 28, 20265 min read

Boost your test coverage with CircleCI Chunk AI agent

Roger Winter

Content Marketing Manager

Test coverage is one of those metrics everyone agrees matters until it’s time to actually write the tests. Between shipping features, fixing bugs, and handling production issues, writing comprehensive tests for edge cases and error paths often falls to the bottom of the backlog. The result is coverage gaps that accumulate technical debt and leave your codebase vulnerable to regressions.

As AI-powered development tools reshape how we write code, the volume and velocity of changes is accelerating. AI coding assistants can generate features in minutes that would have taken hours, but test coverage often lags behind. This creates a new challenge: how do you maintain quality at AI-scale development speeds?

Chunk, CircleCI’s autonomous CI/CD agent, addresses this by bringing AI capabilities directly into your continuous integration pipeline. Unlike AI coding assistants that operate in your IDE, Chunk works within CircleCI where it has access to your build history, test results, and pipeline data. It can analyze your codebase, identify untested code paths, and generate tests that meaningfully improve your coverage. In this guide, you’ll learn how to use Chunk to extend test coverage automatically.

Setting up Chunk

To get started with Chunk, you’ll need a CircleCI account with a project already running pipelines. If you’re new to CircleCI, check out the getting started guide to connect your repository.

You can follow along with your own project or use our demo project on GitHub if you’d like a ready-made example.

Once your project is running in CircleCI:

  1. Select Chunk from the CircleCI web app sidebar.
  2. Click Set up Chunk and follow the prompts to authorize GitHub access. Chunk requires read access to analyze your repository and write access to create pull requests with its changes.
  3. Connect your Anthropic or OpenAI API key when prompted. Chunk uses your own API credentials, so your code is never sent to external providers for model training and data stays under your control.

2026-01-28-chunk-testing-image-1

Chunk integrates directly with your existing CircleCI pipelines without requiring any reconfiguration. Once authorized, it can analyze both your repository code and your build history to understand how your project works. For complete setup instructions, see the Chunk documentation.

Asking Chunk to extend test coverage

With Chunk enabled, click to Chunk from the sidebar. You’ll see a prompt interface where you can describe what you want Chunk to do.

Start with a simple prompt:

Extend my test coverage

2026-01-28-chunk-testing-image-2

Click Submit and Chunk begins working. Because Chunk operates within your CI/CD environment, it has access to your test history, coverage reports, and build artifacts. It uses this data to identify modules with low or missing coverage, generate test cases, validate them against your test suite, and prepare changes for review.

Reviewing the Results

When Chunk completes its analysis, you’ll see a summary of what it found and the changes it made. From this page, you can review the details and decide whether to open a pull request. If you’re not satisfied with the changes, you can skip the PR and refine your prompt instead.

2026-01-28-chunk-testing-image-3

Chunk explains what changes it made:

Changes

Batch Processor: Split generic invalid input test into specific cases
(null, non-array, object) and added test for promise-returning non-async
transforms

Pipeline Processor: Added validation tests for step name/function
requirements, added getSteps() method tests, and added promise handling
tests for null/undefined results

CSV to JSON Transformer: Added input validation tests (undefined,
non-string, object) and extensive edge case tests (empty lines,
whitespace, missing values, extra values, custom delimiters)

Normalize Transformer: Added nested object tests (uppercase, deeply
nested, null values), primitive value tests, and non-string object
value preservation tests

Currency Validator: Added null/undefined validation tests and formatting
tests for values with/without commas

Date Validator: Added null/undefined/non-string validation tests and
normalization tests for whitespace handling

Email Validator: Added null/undefined/non-string input validation tests

Phone Validator: Added null/undefined/non-string validation tests,
invalid character tests, and formatting output tests

These changes improve test coverage by adding edge case handling, input
validation, and specific error message verification.

If the changes look good, click Open Pull Request to create a PR in your repository.

2026-01-28-chunk-testing-image-4

Before merging, review the generated tests to ensure they test meaningful behavior and that assertions match your module’s expected functionality.

More targeted prompts

The simple “Extend test coverage” prompt works well for general improvements. For more control over what Chunk generates, try targeted prompts.

To target a specific module, run:

Write unit tests for src/exporters/jsonExporter.js

To specify the types of tests you want, run:

Add tests for src/exporters/jsonExporter.js covering:
- Error handling for null/undefined inputs
- Edge cases for empty arrays and objects
- All option combinations for exportToJson

To focus on a single function, run:

Add tests for the parseJsonSafely function including valid JSON,
malformed JSON, and non-string inputs

The more specific you make your prompt, the more targeted Chunk’s output will be.

Advanced configuration

Once you’re comfortable with the basics, you can fine-tune how Chunk operates with your project.

Environment setup

For projects with complex dependencies, external services, or specific runtime requirements, you can provide a .circleci/cci-agent-setup.yml file that tells Chunk exactly how to prepare your test environment.

This is useful when your project requires:

  • Database setup: If your tests need PostgreSQL, MySQL, or other databases
  • External services: Redis, Elasticsearch, or other services running in containers
  • Custom dependencies: System packages, specific runtime versions, or build tools
  • Environment variables: Configuration that tests need to run properly

The file uses the same CircleCI configuration syntax you’re already familiar with. Here’s an example for a Node.js project with PostgreSQL:

version: 2.1

workflows:
  main:
    jobs:
      - cci-agent-setup

jobs:
  cci-agent-setup:
    docker:
      - image: cimg/node:20.11
      - image: cimg/postgres:15.3
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: npm ci
      - run:
          name: Setup Database
          command: |
            psql -c "CREATE DATABASE test_db;" -U postgres

Focus on environment preparation only. Don’t include actual test execution commands. Chunk will determine how to run tests based on your main config.yml.

Chunk will attempt to automatically create this file if needed. You can also manually generate one. Go to Organization Settings -> Chunk Tasks. Click the menu (…) for your task. Click Chunk Environment, then click Create File in GitHub. For more details, see the Chunk environment documentation.

Custom instructions

To align generated tests with your team’s coding standards, create a claude.md or agents.md file in your repository root. Document your test style preferences, naming conventions, and edge cases you want covered. Chunk reads these files and applies your preferences when generating code.

Chunk in the AI development ecosystem

Chunk is part of CircleCI’s broader investment in AI-powered development tools. While AI coding assistants like Cursor and Claude Code help you write code faster, Chunk operates at the CI/CD layer where it can validate, test, and maintain that code automatically.

For teams using AI coding assistants, CircleCI also offers the CircleCI MCP Server, which connects AI assistants directly to your pipelines using the Model Context Protocol. This lets your IDE-based AI tools access build logs, test results, and pipeline status without leaving your editor. Together, Chunk and the MCP server create an integrated AI development workflow where code generation, validation, and maintenance all benefit from intelligent automation.

Conclusion

Maintaining comprehensive test coverage doesn’t have to be a manual grind. Chunk analyzes your codebase, identifies untested paths, and generates tests that exercise them, transforming a time-consuming maintenance task into an automated workflow. As AI-powered development accelerates the pace of code changes, having an autonomous agent that keeps your test suite comprehensive becomes essential.

Ready to try it yourself? Sign up for a free CircleCI account and enable Chunk to start improving your test coverage automatically.