I am using mocha as test framework in my project.When I write unit test,I prefer to:
describe('cooperation', () => {
describe('create cooperation', done => {
it('should create a cooperation between A and B', done => {
//make a post request to create a cooperation between A and B
//res.body.should.deepEqual({/*cooperation object*/})
done();
});
});
describe('get cooperation', done => {
before(done => {
//clear any cooperation in database
//initital cooperation between A and B by fixture tool
done();
});
it('get A's partner', done => {
//make a get request to get cooperation of A
//res.body should have B
});
});
});
But my workmates prefer to:
describe('cooperation', () => {
it('should create a cooperation between A and b', done => {
//make a post request to create a cooperation between A and B
//res.body.should.deepEqual({/*cooperation object*/})
done();
});
it('get A's partner', done => {
//make a get request to get cooperation of A
//res.body should have B
});
});
I want to know which is better and why?
I'd go with your team-mates. In my opinion, your style has non-necessary bloat and has worse readability compared to the other one. I think you should ask yourself, with your approach, that what do you expect to achieve more that is better than the other one?
Keep your tests simple and clean.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments