slackapi / slackapi/bolt-python
Document about the ways to write unit tests for Bolt apps
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.3k
- 派生
- 288
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 10
描述
I am looking to write unit tests for my Bolt API, which consists of an app with several handlers for events / messages. The handlers are both decorated using the app.event decorator, and make use of the app object to access things like the db connection that has been put on it. For example:
# in main.py
app = App(
token=APP_TOKEN,
signing_secret=SIGNING_SECRET,
process_before_response=True,
token_verification_enabled=token_verification_enabled,
)
app.db = db
# in api.py:
from .main import app
@app.command("/slashcommand")
def slash_command(ack, respond):
ack()
results = app.db.do_query()
respond(...)
The thing is, I cannot find any framework pointers, or documentation, on how I would write reasonable unit tests for this. Presumably ones where the kwargs like ack and respond are replaced by test doubles. How do I do this?
The page URLs
Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 https://slack.dev/bolt-python/ 上的 Bolt for Python 文档开始,查看 main.py 和 api.py 中展示的 handler 结构,包括 app.command、app.event、app.db、ack 和 respond。记录一种合理的单元测试方法,用于测试这些 handler,包括为 handler 参数和 app 依赖项提供测试替身,并附上能够清楚说明预期行为的示例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation, testing-qa
- Issue 类型
- 文档
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100