Skip to main content

Coverage-driven automatic unit test generator for Python projects.

Project description

Pyster

Build Status Code Style Coverage Status

Pyster is a coverage-driven automatic unit test generator for Python projects.

Pre-request

Usage

# Stage 1: Init pyster config file
python3 -m pyster.init \
  --project_path <path-to-project> \
  --module_name <module-for-testing> \
  --path_runtime <runtime-analysis-code>
# Stage 2: Generate unit tests
python3 -m pyster.gen \
  --project_path <path-to-project> \
  --module_name <module-for-testing> \
  --user_tests <list-of-existing-test-files> \
  --timeout <timeout-limit> \
  --coverage <coverage-target>

# Run Stage 1 and Stage 2 together:
python3 -m pyster \
  --project_path <path-to-project> \
  --module_name <module-for-testing> \
  --path_runtime <runtime-analysis-code> \
  --user_tests <list-of-existing-test-files> \
  --timeout <timeout-limit> \
  --coverage <coverage-target>

Test

pytest tests

Sample execution

# Phase 1
python3 -m pyster.init --project_path tests/foobar --module_name foobar.foobar
# Phase 2
python3 -m pyster.gen --project_path tests/foobar --module_name foobar.foobar -t 1 -c 80

Concept

  • Use built-in Python functions to obtain all methods in a Python class.
  • According to the methods input, randomly generate an object instance and function arguments, with special inputs (0, -1 for integers, [] for lists and None for objects also into consideration). Use coverage.py third-party library to get the coverage rate increment after calling the randomly generated function call.
  • Repeat step 2 until we reached 100% coverage rate or the target coverage rate from user input, or the specified timeout is reached.
  • Dump all auto-generated unit tests into a test file and save it into the project test suite directory, together with a before/after coverage rate of the class.

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

pyster-python-0.0.1.tar.gz (11.0 kB view hashes)

Uploaded Source

Built Distribution

pyster_python-0.0.1-py3-none-any.whl (15.1 kB view hashes)

Uploaded Python 3

Supported by

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