Skip to main content

Rehearser makes writing reliable unit tests super easy!

Project description

🎭 Rehearser - We make writing reliable unit tests and contract tests super easy! 🎭

Rehearser is a robust and intuitive tool designed to save much of your time in unit and contract testing creation. With its unique approach to replaying interactions, Rehearser ensures your software components interact seamlessly and error-free.

Key Features:

  • Easy to use 🎭
  • Replay Interactions for python method, HTTP or etc... 🔄
  • User-Friendly Interface 🖥️
  • Integration with Popular Testing Frameworks 🤖
  • Support for Multiple Programming Languages 🐍🌐☕
  • Open Source ❤️
  • Community Support 👫

Join the Rehearser community and make your testing process as smooth as a rehearsal! 🎭

#UnitTesting #ContractTesting #TestingTools #OpenSource #DeveloperTools #Rehearser

Tutorial

1. Installation:

pip install rehearser

2. Creating a Rehearser Proxy:

Create Rehearser Proxies for instances ProductService() and UserService(), respectively.

from rehearser import RehearserProxy
from examples.example1.usage import ProductService, UserService

rp_product = RehearserProxy(ProductService())
rp_user = RehearserProxy(UserService())

3. Generate Interactions:

Generate mock objects using the interactions created in the previous step.

# Apply patches to UserService and ProductService
with patch(
    "rehearser.examples.example1.usage.UserService",
    return_value=rp_user,
), patch(
    "rehearser.examples.example1.usage.ProductService",
    return_value=rp_product,
):
    # Rehearsal run
    Usage().run_example()

    # Generate interactions files
    rp_user.set_interactions_file_directory("./raw_files/rehearser_proxy/")
    rp_user.write_interactions_to_file()
    rp_product.set_interactions_file_directory("./raw_files/rehearser_proxy/")
    rp_product.write_interactions_to_file()

**4. Write Unit Test **:

Run your unit test with patched mocks now.

# Instantiate mock objects
mock_users = MockGenerator(
    interactions_src="./raw_files/rehearser_proxy/UserService/latest_interactions.json"
).create_mock()
mock_products = MockGenerator(
    interactions_src="./raw_files/rehearser_proxy/ProductService/latest_interactions.json"
).create_mock()

# Apply patches to UserService and ProductService
with patch(
    "rehearser.examples.example1.usage.UserService",
    return_value=mock_users,
), patch(
    "rehearser.examples.example1.usage.ProductService",
    return_value=mock_products,
):
    # Instantiate Usage with the mocked services
    result = Usage().run_example()

    # Insert your test assertions here
    self.assertTrue(result, "run_example() failed")

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

rehearser-0.1.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

rehearser-0.1.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file rehearser-0.1.2.tar.gz.

File metadata

  • Download URL: rehearser-0.1.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for rehearser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 58c16a92a9636df2462468a42eb3daac52c2f49c3600b6c077c5b05c58d4b56e
MD5 a22891d0394174e6e4adbf3ff7b400ea
BLAKE2b-256 45a0889088fa904227ebeab2a8ac3e267c85425dff57cd9f1e37a524e7510833

See more details on using hashes here.

File details

Details for the file rehearser-0.1.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for rehearser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e1367a181230fb8fa44be9dd0a45927816da20fc4d91182a0951a5defdbc8ea3
MD5 1986ed46a8bd462e310e2e08dbae6d9c
BLAKE2b-256 ed67e42eb66b9435bacb81412295ca87c48f6fed2d17bf72a4ee59393a425c08

See more details on using hashes here.

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