我正在为数据库驱动程序编写单元测试。在第一个测试中,我创建了一些我打算稍后在测试中使用的对象。我想编写测试,以便如果这个(关键)步骤失败,其他一切都会停止。我这样做了,但感觉有点太老套了……在这种情况下,最佳做法是什么?
"create constructors and layers": function( test ){
var self = this;
try {
self.shared.personLayer = new self.Layer( 'people', { name: true, surname: true, age: true } );
test.ok( self.shared.personLayer );
self.shared.personLayerNoDb = new self.LayerNoDb( 'people', { name: true, surname: true, age: true }, self.db );
test.ok( self.shared.personLayerNoDb );
var personLayerOverwriteDb = new self.Layer( 'people', { name: true, surname: true, age: true }, self.db );
test.ok( personLayerOverwriteDb );
self.shared.ranks = new self.Layer( 'ranks', { name: true, number: true } );
test.ok( self.shared.ranks );
} catch( e ){
console.log("Error: couldn't create layers, aborting all tests...");
console.log( e );
console.log( e.stack );
process.exit();
}
test.done();
},