新模式 - 扫描整个存储库,自动识别测试文件,自动收集每个测试文件的上下文,并使用新测试扩展测试套件。在此处查看更多详细信息。
欢迎来到封面。这个重点的项目利用生成的AI来自动化和增强测试的生成(目前主要是单位测试),以简化开发工作流程。 Cover-Agent可以通过终端运行,并计划将其集成到流行的CI平台中。
我们邀请社区协作并帮助扩展封面代理的能力,继续作为自动化单元测试生成域中的尖端解决方案的发展。我们还希望激发研究人员利用这种开源工具来探索新的测试生成技术。
该工具是一套更广泛的公用事业套件的一部分,旨在自动化软件项目的单元测试。利用先进的生成AI模型,它旨在简化和加快测试过程,以确保高质量的软件开发。该系统包括几个组件:
在开始之前,请确保您有以下内容:
OPENAI_API_KEY在您的环境变量中设置,这是调用OpenAI API所需的。pytest-cov 。运行pytest时,添加--cov-report=xml选项。cover_agent/CoverageProcessor.py做出贡献如果直接从存储库运行,您也需要:
封面代理可以作为python pip软件包安装,也可以作为独立可执行文件运行。
要通过github运行以下命令直接安装Python Pip软件包:
pip install git+https://github.com/Codium-ai/cover-agent.git可以在系统上安装任何python环境(例如在不包含python的码头容器中)运行二进制。您可以通过导航到项目的发行页来下载系统的版本。
运行以下命令以安装所有依赖关系并从源运行项目:
poetry install下载可执行文件或安装PIP软件包后,您可以运行封面代理以生成和验证单元测试。使用以下命令从命令行执行它:
cover-agent
--source-file-path " <path_to_source_file> "
--test-file-path " <path_to_test_file> "
--project-root " <path_to_project_root> "
--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> "您可以使用下面的示例代码尝试封面代理。 (请注意,usage_examples文件提供了更多有关如何使用封面代理的详细示例)
请按照templated_tests/python_fastapi/ Directory中的readme.md文件中的步骤设置环境,然后返回存储库的根,然后运行以下命令将测试添加到Python Fastapi示例:
cover-agent
--source-file-path " templated_tests/python_fastapi/app.py "
--test-file-path " templated_tests/python_fastapi/test_app.py "
--project-root " templated_tests/python_fastapi "
--code-coverage-report-path " templated_tests/python_fastapi/coverage.xml "
--test-command " pytest --cov=. --cov-report=xml --cov-report=term "
--test-command-dir " templated_tests/python_fastapi "
--coverage-type " cobertura "
--desired-coverage 70
--max-iterations 10例如,将GO cd使用templated_tests/go_webservice中的示例,请按照README.md设置项目。要处理覆盖范围报告,您需要安装gocov和gocov-xml 。运行以下命令安装以下工具:
go install github.com/axw/gocov/[email protected]
go install github.com/AlekSi/[email protected]然后运行以下命令:
cover-agent
--source-file-path " app.go "
--test-file-path " app_test.go "
--code-coverage-report-path " coverage.xml "
--test-command " go test -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml "
--test-command-dir $( pwd )
--coverage-type " cobertura "
--desired-coverage 70
--max-iterations 1有关将Java cd在templated_tests/java_gradle中使用的示例,请在readme.md之后设置项目。要使用Jacoco覆盖范围报告,请遵循readme.md要求部分:然后运行以下命令:
cover-agent
--source-file-path= " src/main/java/com/davidparry/cover/SimpleMathOperations.java "
--test-file-path= " src/test/groovy/com/davidparry/cover/SimpleMathOperationsSpec.groovy "
--code-coverage-report-path= " build/reports/jacoco/test/jacocoTestReport.csv "
--test-command= " ./gradlew clean test jacocoTestReport "
--test-command-dir= $( pwd )
--coverage-type= " jacoco "
--desired-coverage=70
--max-iterations=1一些调试文件将在存储库中本地输出(这是.gitignore的一部分)
run.log :倒在stdout记录器的副本test_results.html :一个结果表,其中包含每个生成的测试的以下内容:stderrstdout如果设置环境变量WANDB_API_KEY ,则提示,响应和其他信息将记录在权重和偏见中。
该项目使用LITELLM与OpenAI和其他托管LLMS进行通信(迄今为止支持100多个LLMS)。要使用除OpenAI默认值以外的其他模型:
--model选项调用模型的名称。例如(如Litellm快速启动指南中发现):
export VERTEX_PROJECT= " hardy-project "
export VERTEX_LOCATION= " us-west "
cover-agent
...
--model " vertex_ai/gemini-pro " export OPENAI_API_KEY= " <your api key> " # If <your-api-base> requires an API KEY, set this value.
cover-agent
...
--model " openai/<your model name> "
--api-base " <your-api-base> " export AZURE_API_BASE= " <your api base> " # azure api base
export AZURE_API_VERSION= " <your api version> " # azure api version (optional)
export AZURE_API_KEY= " <your api key> " # azure api key
cover-agent
...
--model " azure/<your deployment name> " 有关如何为该项目做出贡献的更多信息,请参见开发。
以下是计划特征的路线图,具有当前的实施状态:
Qodoai的使命是使忙碌的开发团队能够提高并保持其代码完整性。我们提供各种工具,包括我们的开源工具的“ PRO”版本,这些工具旨在处理企业级代码复杂性并符合多重代码库。
尝试封面代理的Pro版本Qodo Cover!