Context
The most expedient way to test anything is to be exhaustive. This is called the powerset model. Easy to get started but can cost us in the long term, coz code is liability. The correct model to hold when writing a test is to ask:
what it does for code coverage, more is better
how it should identify incorrect behavior of the subject under test without using a powerset model
Problem
There are just too many test cases that do not add value. Value here would be to increase code coverage with the least number of test cases.
For example:
sub-context-of-conduit-testing: 'testing suri field...'
- 'should not allow no suri'
- 'should not allow undefined suri'
- 'should not allow null suri'
- 'should not allow empty suri'
- 'should not allow non-url suri'
Can be reduced to:
// unhappy path, happy path is covered elsewhere...
// notice there is no sub-context just to test a field
- 'should reject invalid suri'
- test for null, undefined (note: in JS empty, undefined, null are falsey)
- test for invalid url
Exemplar
it('should reject invalid suri', async () => {
const ct = await helpers.fakeConduit();
// in js: blank, undefined, null, not-present are all falsey
ct.suri = undefined;
const res = await Api()
.post(`/conduits`)
.set('Authorization', `Token ${jakeUser.token}`)
.send({ conduit: ct });
expect(res.status).to.equal(422);
expect(Object.keys(res.body.errors)).to.include('suri');
// test for invalid url, notice we are re-using `ct`
ct.suri = 'not-in-url-format';
const res = await Api()
.post(`/conduits`)
.set('Authorization', `Token ${jakeUser.token}`)
.send({ conduit: ct });
expect(res.status).to.equal(422);
expect(res.body.error.errors[0].path).to.equal('suri');
});
Acceptance Criteria
[x] The scope is isolated to reduction of test cases in test-rest only
[x] Code coverage should remain at the same level or increase from the baseline
Context The most expedient way to test anything is to be exhaustive. This is called the
powerset
model. Easy to get started but can cost us in the long term, coz code is liability. The correct model to hold when writing a test is to ask:powerset
modelProblem There are just too many test cases that do not add value. Value here would be to increase code coverage with the least number of test cases.
For example:
Can be reduced to:
Exemplar
Acceptance Criteria
test-rest
only