Skip to main content

No project description provided

Project description

AI Test Craft

Automated Unit Test Generation for Python

AITestCraft is a Python package that assists developers in generating unit tests for their code. It leverages OpenAI's GPT models to create test cases based on the structure and requirements of your codebase.

Features:

  • Automated generation of unit tests from JSON configuration.
  • Support for Python 3.10 and other versions.
  • Allows for additional comments to guide test case creation.
  • Sequential file processing for context-aware test generation.

Prerequisites:

To use AITestCraft, you need an OpenAI API key. To obtain it, follow these steps:

  1. Sign up for an account at OpenAI.
  2. Navigate to the API section and follow the instructions to generate your API key.

Before running AITestCraft, ensure that your OPENAI_API_KEY environment variable is set with your OpenAI API key. Alternatively, you can specify a custom environment variable name for your OpenAI API key using the command-line interface.

Installation:

Install AITestCraft using pip:

pip install aitestcraft

Usage:

First, set the OPENAI_API_KEY environment variable or a custom one:

For Unix-based systems (Linux/Mac):

export OPENAI_API_KEY='your_api_key_here'

For Windows:

set OPENAI_API_KEY=your_api_key_here

Alternatively, use a custom environment variable:

export MY_ENV_VAR_NAME='your_api_key_here'

To generate unit tests, create a JSON configuration file named to-test.json:

{
  "language": "python",
  "language_version": "3.11",
  "model": "gpt-3.5-turbo",
  "overwrite": "never",
  "additional_comments": [
    "Use functions for each testcase and not unittest.TestCase"
  ],
  "files": [
    {
      "code": "aitestcraft/conf_representation.py",
      "test": "tests/test_conf_representation.py"
    },
    {
      "code": "aitestcraft/validators.py",
      "test": "tests/test_validators.py"
    },
    {
      "code": "aitestcraft/ai_generator.py",
      "test": "tests/test_ai_generator.py"
    }
  ]
}

Then run the package with:

aitestcraft to-test.json

Or if you're using a custom environment variable for the API key:

python aitestgen.py --open-ai-env-var MY_ENV_VAR_NAME ./to-test.json

Configuration Fields:

  • language: Programming language used.
  • language_version: Version of the programming language.
  • model: OpenAI model used for generating tests.
  • overwrite: ["neve" / "always"] If set to "never", existing test files will not be overwritten.
  • additional_comments: Optional, global comments for test generation.
  • files: A list of objects representing the source code and the test files.

In the files, if a comment starts with AI-TEST, it indicates a message for the AI to include specific demands for the next line, like so:

# AI-TEST: don't test this condition

Note:

The generated tests may require minor adjustments to fit the exact needs of your project.

Order the files in to-test.json from the most standalone files to those with the most dependencies. This helps to provide context that can improve the quality of the generated tests.

Disclaimer:

The test generation is not guaranteed to be perfect and might need adjustments to work seamlessly with your codebase.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai-test-craft-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_test_craft-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file ai-test-craft-0.1.0.tar.gz.

File metadata

  • Download URL: ai-test-craft-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for ai-test-craft-0.1.0.tar.gz
Algorithm Hash digest
SHA256 02b897d4c8e781f881b19545b0aa75f8a7941b375ef104c4bf0362415e719c85
MD5 d2880b6620b39172237a5952f4d45348
BLAKE2b-256 39d95b1455216d3fbb63ff0e81d0676b3750dd42e8760b6d7abcafc55b718ae9

See more details on using hashes here.

File details

Details for the file ai_test_craft-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_test_craft-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for ai_test_craft-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75bb1cd1227a971cedc90d46f304c6b22a9827c20c92d8ff9282b36bb2cef907
MD5 36fd6a975d4f280766fa9b78fe774f9e
BLAKE2b-256 adc99efeacf6db818f3ac27e8445a41fc8e0d9b9ffdaa293e3c8687484d93480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page