Pythagora: Revolutionizing Automated Test Generation
Pythagora is a groundbreaking tool designed to make automated tests fully autonomous. Leveraging the power of GPT-4, Pythagora enables developers to create unit tests with minimal effort. With a single command, high-quality tests are generated, helping developers maintain robust codebases without the usual time-consuming manual effort.
Visual Studio Code Extension
For Visual Studio Code users, Pythagora offers a convenient extension that can be downloaded from the Visual Studio Marketplace. This extension integrates seamlessly, making automated test generation an even smoother process.
Quickstart Guide
Getting started with Pythagora is simple:
-
Install Pythagora using npm:
npm i pythagora --save-dev
-
Add your API key.
-
Run the test generation command from the root directory of your repository:
npx pythagora --unit-tests --func <FUNCTION_NAME>
Make sure the function you want to test is exported from a file.
Expand Your Test Suite
To enhance code coverage or tackle more edge cases within an existing test suite, Pythagora offers an expansion feature:
npx pythagora --expand-unit-tests --path <PATH_TO_YOUR_TEST_SUITE>
Demo and Examples
To see Pythagora in action, check out the demo videos and example projects:
- Lodash Repository: 1604 tests generated, identifying critical bugs and edge cases.
- Node-fs-extra Repository: In just 30 minutes, 98 tests were generated, detecting important bugs.
How Does Pythagora Work?
Pythagora employs an innovative approach using the following steps:
- It identifies the function to test.
- It finds all functions called within that function through AST (Abstract Syntax Tree) parsing.
- The relevant code is sent to the Pythagora server, generating tests using GPT-4.
Pythagora is open-source, fostering transparency and collaboration. For those interested, the server and its prompts are available on GitHub.
Configuration and Options
Pythagora requires either an OpenAI or Pythagora API Key for test generation. Configuration can be done with:
npx pythagora --config --pythagora-api-key <API_KEY>
Additionally, various options allow targeted test generation, whether for a single function, a file, or an entire folder.
Running and Reviewing Tests
Once tests are generated, they can be executed using Jest:
npx jest ./pythagora_tests/
It’s essential to review tests before integrating them into the codebase, ensuring accuracy and thoroughness.
Frequently Asked Questions
- Accuracy of Tests: Best suited for standalone functions, Pythagora excels in finding edge cases and catching bugs.
- Reviewing Tests: It's recommended to examine generated tests for precision before committing.
- Language and Framework Support: Currently supports JavaScript, with potential for expanded language support.
- Handling Sensitive Code: Be cautious with proprietary code, as it interacts with external GPT services.
Alpha Version and Engagement
As an alpha version, Pythagora invites feedback and suggestions for improvement. Users can connect via Discord or subscribe for updates here.
Pythagora is on a mission to transform the way automated tests are created, making the process more efficient, effective, and accessible for developers worldwide. If you find value in this resource, consider starring the Pythagora repository on GitHub to support the project.