https://github.com/diegojromerolopez/slack-bolt-testcase
A simple unittest TestCase class to use it in your Slack Bolt App unittest tests
https://github.com/diegojromerolopez/slack-bolt-testcase
chatbot slack slack-bolt test unittest
Last synced: 4 months ago
JSON representation
A simple unittest TestCase class to use it in your Slack Bolt App unittest tests
- Host: GitHub
- URL: https://github.com/diegojromerolopez/slack-bolt-testcase
- Owner: diegojromerolopez
- License: mit
- Created: 2025-03-21T18:17:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-22T19:11:27.000Z (over 1 year ago)
- Last Synced: 2025-11-11T20:31:18.064Z (8 months ago)
- Topics: chatbot, slack, slack-bolt, test, unittest
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slack-bolt-testcase

[](https://opensource.org/licenses/MIT)
[](https://github.com/diegojromerolopez/slack-bolt-testcase/graphs/commit-activity)
[](https://www.python.org/)
[](https://pypi.python.org/pypi/slack-bolt-testcase/)
[](https://pypi.python.org/pypi/slack-bolt-testcase/)
[](https://pypi.python.org/pypi/slack-bolt-testcase/)
[](https://pypi.python.org/pypi/slack-bolt-testcase/)
A simple unittest TestCase class to use it in your Slack Bolt App unittest tests
## Introduction
The [Slack bolt library](https://github.com/slackapi/bolt-python) and the
[Slack SDK](https://github.com/slackapi/python-slack-sdk) for Python are the best and official ways of implementing
Slack bots in Python. However, there is a small piece missing there: no official documentation about how to do
tests with the standard unittest library that allow developers to test that they have registered their handlers correctly.
slack-bolt-testcase fixes that.
## Requirements
- Python >= 3.9
- slack_bolt~=1.23.0
- slack_sdk~=3.35.0
## Use
To use this TestCase, you just need to inherit from [EventTestCase](/slack_bolt_testcase/event_test_case.py)
and make sure you have registered your event handlers
in the [AppTestCase.app](/slack_bolt_testcase/app_test_case.py).
```python
from unittest.mock import call
from slack_bolt import Say
from slack_bolt_testcase.event_test_case import EventTestCase
# Inherit from the EventTestCase
class TestEventExample(EventTestCase):
def test_handled_event(self):
# Make sure you have registered your events in a way with the self.app mocked Slack App object
# you can do it here or pass the self.app object to a register function.
@self.app.event('app_mention')
def handle_message_events(event: dict[str, str], say: Say):
# Ensure we are receiving the right text
if event.get('text') == 'hello':
event_type = event.get('type')
say(f'Hello the handler handled a(n) {event_type}!')
# Trigger the event
self.trigger_event(event_type='app_mention', text='hello', user='U12345')
# Check the assertions
self.assertEqual(
[call(f'Hello the handler handled a(n) app_mention!')],
self.mock_say.call_args_list,
)
```
More examples in the [tests folder](/slack_bolt_testcase/tests).
## License
[MIT](/LICENSE)
## Disclaimer
Slack is a trademark of Slack Technologies, LLC. This project is not affiliated with, endorsed by, or sponsored by
Slack Technologies, LLC. The use of the name "Slack" in this repository is solely for descriptive purposes and does
not imply any association or intent to infringe on any trademarks.