Skip to main content

Automated unit test generation tool for Python.

Project description

TestGenie

TestGenie is an automated unit test generation tool for Python that supports multiple test generation strategies, including static AST analysis, fuzz testing, feedback-directed random testing, and reinforcement learning.
Built with a modular Pipe and Filter architecture, it analyzes Python source code to extract function metadata, generates meaningful test cases, and outputs executable test suites in formats like Unittest, PyTest, or Doctest.
The system can also measure and report code coverage and safely execute tests in Docker containers.
TestGenie aims to reduce manual testing effort, improve coverage, and explore the potential of learning-based approaches for optimizing test generation.


Installation

Make sure you have Python 3.10+ and Poetry installed.

Install dependencies:

poetry install

Activate the virtual environment:

poetry shell

Running the CLI

To invoke the test generator, run:

poetry run python -m testgen.main <file_path> [options]

Required Argument:

  • <file_path>: Path to the Python module you want to analyze.

Command-Line Options

Command/Flag Description
--output, -o <path> Path to output directory for generated test files (default: ./tests)
--generate-only, -g Only generate test code, skip running tests and measuring coverage
--test-mode <mode> Set the test analysis strategy: ast (default), random, fuzz, or reinforce
--test-format <format> Set the test output format: unittest (default), pytest, or doctest
--safe Run test generation inside a Docker container for isolation and safety
--query, -q Query the database for test cases, coverage data, and test results for a specific file
--db <db_path> Path to SQLite database file (default: testgen.db)
--reinforce-mode <mode> Set mode for reinforcement learning: train (default) or collect
--visualize, -viz Visualize generated test coverage graphs using Graphviz
--debug Enable debug logging output
--log-file <path> Save logs to the specified file instead of only printing to the console

Examples

Generate and run unit tests for a Python module:

poetry run python -m testgen.main mymodule.py

Generate tests using fuzzing strategy and output to a custom directory:

poetry run python -m testgen.main mymodule.py --test-mode fuzz --output generated_tests/

Run reinforcement learning-based test generation:

poetry run python -m testgen.main mymodule.py --test-mode reinforce

Query previously generated test results from the database:

poetry run python -m testgen.main mymodule.py --query

Safely generate tests inside a Docker container:

poetry run python -m testgen.main mymodule.py --safe

Features

  • Static analysis using Python AST
  • Fuzz testing using randomized input generation
  • Feedback-directed random testing
  • Reinforcement learning-based test case optimization
  • Supports Unittest, PyTest, and Doctest formats
  • Code coverage measurement and reporting
  • Docker sandboxing for safe test execution
  • SQLite database integration for tracking tests and results
  • CLI visualization of test coverage graphs

Requirements

  • Python 3.10+
  • Poetry
  • (Optional) Docker (for safe mode execution)

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

testgenie_py-0.2.8.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

testgenie_py-0.2.8-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file testgenie_py-0.2.8.tar.gz.

File metadata

  • Download URL: testgenie_py-0.2.8.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for testgenie_py-0.2.8.tar.gz
Algorithm Hash digest
SHA256 97d27a94a099c5431a1e52abefc6e39db081589bd1a90e11df13761754f431c2
MD5 b848d7fa93ae13c787ea7f5eb46f7a2d
BLAKE2b-256 14f8511e052abba4b798f3605779026a9e14af1aa90a4aea66e3747b45077db5

See more details on using hashes here.

File details

Details for the file testgenie_py-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: testgenie_py-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2

File hashes

Hashes for testgenie_py-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c3a356d93a9668825b8e9570407974c8e0723d58feb293b13df4138e485c5158
MD5 9014dcd36e658fd11f445bccb9f1e50b
BLAKE2b-256 f5f3f07d7a4b2abf37cf3cb5cd13813fc9c72bd7d1265f157951c966fedd7cc3

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