How to Efficiently Increase Code Coverage with CodiumAI Cover Agent

Nov 28, 2022 | Educational

In the fast-paced world of software development, ensuring that your code is thoroughly tested can be an overwhelming task. The CodiumAI Cover Agent comes to the rescue, automating the generation of unit tests to enhance existing test suites and boost code coverage.

Table of Contents

News and Updates

Stay updated on the latest enhancements to Cover Agent:

  • 2024-06-05: Improved logic for adding new imports and added a usage examples file.
  • 2024-06-01: Integrated comprehensive logging with Weights and Biases. Set the WANDB_API_KEY environment variable to enable this feature.
  • 2024-05-26: Support for nearly any LLM model using LiteLLM.
  • 2024-05-09: First implementation of TestGen-LLM as featured in [Automated Unit Test Improvement using Large Language Models at Meta](https://arxiv.org/abs/2402.09171).

Overview

Cover Agent is designed to simplify the testing process, utilizing advanced Generative AI models. Here’s how it works:

  • Test Runner: Executes test suites and generates coverage reports.
  • Coverage Parser: Ensures that code coverage increases with new tests.
  • Prompt Builder: Gathers codebase data to create prompts for LLM interaction.
  • AI Caller: Generates tests based on the prompts provided.

Installation and Usage

To get started with Cover Agent, follow these instructions:

Requirements

Make sure you have the following:

  • OPENAI_API_KEY: This is needed for API calls.
  • Code Coverage Tool: A Cobertura XML report is required. For Python, use pytest-cov with the --cov-report=xml option.
  • Python: Ensure Python is installed on your system.
  • Poetry: Use for managing Python dependencies. Installation instructions can be found at Poetry Docs.

Standalone Runtime

Install the Cover Agent via Python Pip or run it as a standalone executable.

Python Pip Installation

Run the following command:

pip install git+https://github.com/Codium-ai/cover-agent.git

Binary Installation

Download the release from the project’s release page.

Running the Code

Execute the Cover Agent from the command line using the following command:

cover-agent --source-file-path path_to_source_file --test-file-path path_to_test_file --code-coverage-report-path path_to_coverage_report --test-command test_command_to_run --test-command-dir directory_to_run_test_command --coverage-type type_of_coverage_report --desired-coverage desired_coverage_between_0_and_100 --max-iterations max_number_of_llm_iterations --included-files optional_list_of_files_to_include

For practical examples tailored to different programming languages, refer to the usage_examples file.

Development

If you’re interested in contributing to the project, here’s how you can get set up:

  • Run poetry install to set up your environment.
  • Use poetry run pytest to run tests and generate logs.

Roadmap

Here are the planned features for the future:

  • Enhancements in generating tests across different programming languages.
  • Dealing with a wide variety of testing scenarios.
  • Behavior analysis generation for code under test and focused PR changesets.
  • Integrations with CI/CD platforms like GitHub Actions, Jenkins, etc.

Troubleshooting

If you encounter problems while using Cover Agent, consider the following troubleshooting ideas:

  • Ensure that your OPENAI_API_KEY is correctly configured.
  • Double-check your dependencies; run poetry install again if necessary.
  • Review the command syntax to ensure there are no errors.
  • Seek help from the community on the Discord server or check the issues section of the GitHub repository.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox