loopbackio / loopbackio/loopback-next
Testing your Application: explain why interdependent tests are bad
未关闭
适合新手
还没有人认领这个 Issue。
Docs
good first issue
help wanted
- 主要语言
- TypeScript
- 星标
- 5.1k
- 派生
- 1.1k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 27
描述
In https://github.com/strongloop/loopback4-example-getting-started/pull/2, the proposed acceptance tests are relying on the first test to fill the database with data that's used by subsequent tests:
it('creates a todo', async () => {
item = (await client
.post('/todo')
.send(payload)
.expect(
Object.assign({}, payload, {
id: 1
})
)).body;
});
//...
it('successfully deletes todos', async () => {
await client.del(`/todo/${item.id}`).send();
await client
.get(`/todo/${item.id}`)
.send()
.expect(404);
});
(see https://github.com/strongloop/loopback4-example-getting-started/pull/2#discussion_r147389550)
This is an anti-pattern to avoid:
- if the first test fails, all subsequent tests fail too (because data was not filled in), but with an unhelpful error message is confusing.
- it is not possible to run individual tests on their own, e.g. via
it.only()ormocha -g "test name".
We should extend Data Handling in Testing your Application to mention this pattern and explain why it's a bad thing to do.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 issue 中链接的“Data Handling in Testing your Application”部分开始,然后阅读所引用的示例测试和 pull request 讨论,以了解背景。更新文档,解释相互依赖的测试为何存在问题,以及独立测试如何支持隔离执行;完成的标准是同时涵盖失败级联和 it.only()/mocha -g 的使用。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 1/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100