https://github.com/exasol/test-db-builder-python
Build test databases for integration tests in a compact and convenient way.
https://github.com/exasol/test-db-builder-python
database-testing exasol-integration integration-testing testing
Last synced: about 1 month ago
JSON representation
Build test databases for integration tests in a compact and convenient way.
- Host: GitHub
- URL: https://github.com/exasol/test-db-builder-python
- Owner: exasol
- License: mit
- Created: 2025-12-02T09:41:16.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-03-03T07:30:55.000Z (about 2 months ago)
- Last Synced: 2026-03-03T10:56:49.642Z (about 1 month ago)
- Topics: database-testing, exasol-integration, integration-testing, testing
- Language: Python
- Homepage:
- Size: 361 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
- Security: SECURITY.md
Awesome Lists containing this project
README
Test Database Builder for Python (TDBP)
=======================================
Test Database Builder for Python (TDBP) is a lightweight framework that simplifies database integration testing by providing a fluent API for creating test database objects and test data.
It helps developers write cleaner, more maintainable database integration tests by eliminating boilerplate code and providing a consistent way to set up test data.
TDBP promotes the concept of disposable test setups. The compact code encourages keeping each test independent by having it create its own test dataset.
This also makes reviews much easier, since setup execution and assertions are close to each other.
Please note that TDBP aims at functional tests, where the amount of data required for each test is usually small.
If you need to test with large amounts of data, TDBP is not the right approach. It is especially ill-suited for performance testing.
This project is inspired by Exasol's Test Database Builder for Java (https://github.com/exasol/test-db-builder-java).
Target Audience
---------------
TDBP is designed for:
- Software developers writing database integration tests
- QA engineers automating database tests
- Database developers testing stored procedures and functions
- Anyone needing to create temporary test database objects and data
.. tip:: We recommend using TDBP when:
- You need to create temporary database objects for functional testing
- You want to isolate tests from each other
- You need to repeatedly set up and tear down test data
- You want to make your database tests more readable, maintainable and easy to review
.. warning:: **Do not** use TDBP in any of the situations below:
- Production data management
- Performance testing (use dedicated tools instead)
- Managing persistent database objects
- Complex data modeling (use proper database migration tools)
Quick Start
-------------
We recommend to make the object factory a fixture in your integration test and purge the database before each test. This ensures test isolation.
The object factory needs a database connection. In case of the Exasol dialect, the `pytest-exasol-backend` (https://github.com/exasol/pytest-backend) makes creating an Exasol backend and getting a connection very convenient.
.. code-block:: python3
@pytest.fixture
def factory(connection):
factory = ExasolObjectFactory(connection)
factory.purge_user_objects() # Clean slate for each test
return factory
With that done, the test preparation gets very compact.
.. code-block:: python3
def test_insert_customers(factory):
# Prepare the test database
schema = factory.create_schema("SALES")
table = schema.create_table("CUSTOMERS",
ID="DECIMAL(12,0)", NAME="VARCHAR(255)")
table.insert(1, "Alice").insert(2, "Bob")
# Execute your test
# ...
# Assert the results
# ...
Information for Users
---------------------
* 📖 `User Guide `_: Detailed instructions on using TDBP including examples and best practices