From 8b8d60030fe6594778210fee254e55604f131aa3 Mon Sep 17 00:00:00 2001 From: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 7 Jan 2024 12:56:40 +0100 Subject: [PATCH] Updated Writing Tests (markdown) --- Writing-Tests.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Writing-Tests.md b/Writing-Tests.md index 9f85fb2..92d9da1 100644 --- a/Writing-Tests.md +++ b/Writing-Tests.md @@ -2,7 +2,13 @@ In case you want to practice [test-driven development](https://en.wikipedia.org/ ## Unit Tests Unit tests are performed on a logically encapsulated component of the system. The definition of unit tests in contrast to integration tests is that they have no external dependencies. -@Eldinnie has written an initial POC of a unit test framework for python-telegram-bot, but as the library grew it was not maintained. Perhaps you might be able to help us out here and help in completing the project ;) + +Thanks to PTBs modular structure, integration with unit tests can already be achieved for many use cases without additional tooling. For example, you can + +* manually enqueue updates in the [`Application.update_queue`](https://docs.python-telegram-bot.org/en/stable/telegram.ext.application.html#telegram.ext.Application.update_queue) or directly call [`Application.process_update`](https://docs.python-telegram-bot.org/en/stable/telegram.ext.application.html#telegram.ext.Application.process_update). This allows you to check that verify that updates are being processed as desiderd without fetching any data from Telegram. Note that for this approach, you'll probably want to set [the updater to `None`](https://docs.python-telegram-bot.org/en/stable/telegram.ext.applicationbuilder.html#telegram.ext.ApplicationBuilder.updater) +* mock the networking connection to Telegram, i.e. instead of sending the API requests to Telegram you send them to a fictional backend that you control yourself. That way, your tests can not be corrupted by networking issues and do not need an internet connection. This can be achieved e.g. by subclassing the [`Bot`](https://docs.python-telegram-bot.org/en/stable/telegram.bot.html) class and overriding all methods or by implementing a subclass of [`BaseRequest`](https://docs.python-telegram-bot.org/en/stable/telegram.request.baserequest.html). + +Moreover, @Eldinnie has written an initial POC of a unit test framework for python-telegram-bot, but as the library grew it was not maintained. Perhaps you might be able to help us out here and help in completing the project ;) https://github.com/Eldinnie/ptbtest ## Integration Tests