プロジェクトでテストフレームワークとして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
});
});
どちらが良いのか、そしてその理由を知りたいのですが?
私はあなたのチームメイトと一緒に行きます。私の意見では、あなたのスタイルは不必要な膨満感があり、他のスタイルに比べて読みやすさが劣っています。自分のアプローチで、他のアプローチよりも優れた成果を達成するために何を期待しているのかを自問する必要があると思います。
テストをシンプルかつクリーンに保ちます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加