loopbackio / loopbackio/loopback-next
Testing your Application: explain why interdependent tests are bad
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Data Handling in Testing your Application section linked in the issue, then read the referenced example tests and pull request discussion for context. Update the documentation to explain why interdependent tests are problematic and how independent tests support isolated execution; done means both failure cascading and it.only()/mocha -g usage are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100