新模式 - 掃描整個存儲庫,自動識別測試文件,自動收集每個測試文件的上下文,並使用新測試擴展測試套件。在此處查看更多詳細信息。
歡迎來到封面。這個重點的項目利用生成的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!