我在我的项目中使用mocha作为测试框架。当我编写单元测试时,我更喜欢:
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
});
});
});
但我的同事更喜欢:
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
});
});
我想知道哪个更好,为什么?
答案 0 :(得分:1)
我和你的队友一起去。在我看来,你的风格没有必要的膨胀,并且与其他风格相比具有更差的可读性。我认为你应该问问自己,你的方法是什么,你期望获得更多的东西比另一个更好?
让您的测试简单明了。