AI + TDD Project Introduction
AI + TDD is an innovative approach designed to streamline the development process by leveraging the power of GPT (Generative Pre-trained Transformer) in conjunction with Test-Driven Development (TDD) practices. This unique combination allows developers to write test cases, which then guide the GPT model in writing the necessary code to pass those tests. This results in a highly efficient coding process that ensures functionality is verified right from the start.
What is AI + TDD?
At its core, AI + TDD is a command-line interface (CLI) tool that employs GPT to automate the coding process after a developer has written test cases. By prompting GPT with a well-defined test suite, developers can achieve remarkable accuracy in the generated code—ensuring that it meets the specifications laid out by the tests.
Key Features
- GPT-Powered Automation: The tool harnesses the capabilities of GPT to write code that satisfies the conditions specified in the test cases.
- Integration with TDD: It takes advantage of TDD methodologies, promoting a disciplined approach where tests are written before code, ensuring functionality and reliability.
- Support for Frontend Testing: AI + TDD is capable of handling even frontend tests, illustrated through examples using Jest and Testing Library.
Setup Instructions
To get started with AI + TDD, users must follow these setup steps:
-
Installation of AITDD: First, ensure you have the latest version of Bun, a JavaScript runtime, then install AITDD globally as a CLI using a simple shell command.
curl -sSL https://raw.githubusercontent.com/di-sukharev/AI-TDD/master/install.sh | bash
-
API Key Configuration: Obtain an API key from OpenAI and configure AITDD to use it by storing it locally for secure access.
aitdd config set OPENAI_API_KEY <your_api_key>
-
Test Command Setup: Specify how tests should be run by setting the appropriate command.
aitdd config set RUN_TESTS "npm run test"
Example Use Case
The project provides examples of how developers can use AI + TDD with frontend test suites. These examples show how tests are written in Jest, and how AITDD can handle server responses, user interactions, and error cases effectively. The tool generates the necessary component code, ensuring it passes all specified tests.
Here's a simplified example of how AI + TDD can address testing a frontend component:
-
Test Case Example: Developers can write tests that simulate interactions, such as clicking buttons to load data.
-
Generated Code Example: AI + TDD then generates the code, incorporating React state handling and asynchronous data fetching to ensure the tests pass.
Using AI + TDD
Once set up, developers can easily run AITDD to generate code by executing the following command:
aitdd run
Payment Information
Users are responsible for covering the costs associated with using the OpenAI API. AI + TDD utilizes the latest GPT model; check OpenAI's website for pricing details. Default settings limit response tokens to 2000, but this can be adjusted according to project needs.
Conclusion
AI + TDD represents a significant advancement in the software development domain, offering a seamless integration of AI capabilities within TDD workflows. By automating code generation through meticulously designed tests, it enables developers to enhance productivity while maintaining high standards of code quality.