Skip to main content

A Python framework for declaring Given-When-Then tests

Project description

gwt-test-framework

A Python framework for declaring Given-When-Then tests.

This library helps you organize and structure your tests using the Given-When-Then methodology, making them more readable, maintainable, and descriptive. It enables you to bind the actual code to verbose logic descriptions, fostering a better understanding of test scenarios.

Additionally, it is fully compatible with BDD (Behavior-Driven Development) practices, allowing teams to write tests that reflect the business logic in a clear, human-readable format.

Features

  • Declarative Given-When-Then test structure.
  • Easy-to-use framework for defining tests with clear descriptions.
  • Export test scenarios as Markdown for documentation.

Installation

To install gwt-test-framework, you can use pip:

pip install gwt-test-framework

Usage

Most up-to-date examples of usage can be found in the tests directory.

Basic Usage

To create a Given-When-Then test scenario, you need to create a class that inherits from GivenWhenThenTestScenario and:

  • define the description class attribute.
  • implement the given(), when(), and then() methods.

Example:

from gwt_test_framework import GivenWhenThenTestScenario, GivenWhenThenDescription

class TestValidScenario(GivenWhenThenTestScenario):
    description = GivenWhenThenDescription(
        test_title="TestValidScenario",
        given="Given value is 1",
        when="When value is incremented",
        then="Then value is 2",
    )

    def given(self):
        self.given_value = 1

    def when(self):
        self.given_value += 1

    def then(self):
        assert self.given_value == 2

Running the Test

To run the test scenario, you can call the test() method on the test scenario class:

TestValidScenario.test()

This will execute the given(), when(), and then() methods in order and run the test scenario.

Is compatible with pytest.

Validation

The test() method includes a validation step that ensures the test scenario is correctly defined.

The validation checks:

  • if the given(), when(), and then() methods are implemented.
  • if the description attribute is defined.

Rendering Test Scenarios as Markdown

To render a test scenario as a Markdown string, you can use the render_as_markdown() method on your test scenario class. This method will generate a nicely formatted Markdown string that describes the given, when, and then parts of the scenario.

TestValidScenario.render_as_markdown()

This will return a Markdown string in the following format:

Example

> ### TestValidScenario
    
> **Given:** Given value is 1

> **When:** When value is incremented

> **Then:** Then value is 2

TestValidScenario

Given: Given value is 1

When: When value is incremented

Then: Then value is 2

Contributing

We welcome contributions! If you'd like to contribute, please fork the repository and submit a pull request. Make sure your code passes all tests and includes adequate documentation.

Steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes and commit them.
  4. Push your branch to your forked repository.
  5. Open a pull request against the main branch of the original repository.

License

This project is licensed under the Apache License 2.0 License - see the LICENSE file for details.

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

gwt_test_framework-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

gwt_test_framework-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file gwt_test_framework-0.1.0.tar.gz.

File metadata

  • Download URL: gwt_test_framework-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for gwt_test_framework-0.1.0.tar.gz
Algorithm Hash digest
SHA256 459d1730cd0a93834ac88603e463b436afe505fed3b1d61775349e94f876a2a7
MD5 a3e137b569c1c6394c6ae833207b5c85
BLAKE2b-256 86f2023e057c0ff6685cbffa63d1fc7fe678ca17fb2c3ceca8f9277f8f98215c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gwt_test_framework-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 120e40a336de89c09515ba4dd159d84d57b099aa661aacd032385659aa80ba70
MD5 ea84b211312178f4c811fd213309aaf8
BLAKE2b-256 2762c987d7ef27ff99991397b1af073095f69e37ef817b2a5043774ae462e582

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