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
descriptionclass attribute. - implement the
given(),when(), andthen()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(), andthen()methods are implemented. - if the
descriptionattribute 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
Rendering Test Scenarios on web page
While this library doesn't offer built-in support for rendering test scenarios on a web page, you can easily implement this functionality by:
- Using a Markdown rendering library such as
markdown2ormistune. - Employing an HTML templating engine like
Jinja2orFastHTMLto render the descriptions.
Example using FastHTML:
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:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes and commit them.
- Push your branch to your forked repository.
- Open a pull request against the
mainbranch of the original repository.
License
This project is licensed under the Apache License 2.0 License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gwt_test_framework-0.1.1.tar.gz.
File metadata
- Download URL: gwt_test_framework-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a1cb0cb906b66a89a6e9e202d943efccba17ad40792c745fa6445d2c0f6dd08
|
|
| MD5 |
5b6a10678fa79c0be3780745e55dfcd6
|
|
| BLAKE2b-256 |
1338a0c83e0ca328ceefeca5f67ca61fba2cf56331c8f6a9f16a74b1e1f2296e
|
File details
Details for the file gwt_test_framework-0.1.1-py3-none-any.whl.
File metadata
- Download URL: gwt_test_framework-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13a14f9c907c30e32c15db2941fe9d23baf3737f213553dd3c1360e004c2bdd0
|
|
| MD5 |
780e1585ef17963d9df370a393592f44
|
|
| BLAKE2b-256 |
4e78b7589d18c50f04681599d8163ac463fada2e35b0f76407f4fd996501edc8
|