Group together Jasmine's it specs into a single test run -


i have following situation:

describe('base test suite', function () {     beforeeach(function (done) {         // initialization routine done callback         verylonginitialization(done);     });      it('description of first spec', function (done) {         // first expectations          done();     });      describe('nested suite builds upon base test suite', function () {         beforeeach(function (done) {             secondverylonginitialization(done);         });          it('description of second spec', function (done) {             // second expectations         });     });      describe('second nested suite builds upon base test suite', function () {         beforeeach(function (done) {             thirdverylonginitialization(done);         });          it('description of third spec', function (done) {             // third expectations         });     }); }); 

as can see, have nested test suites. it's important outer beforeeach called before inner one.

  • when outer expectations executed (first spec), verylonginitialization must have been completed.
  • for second spec (first nested spec), it's required verylonginitialization , secondverylonginitialization have been executed sequentially, , completed successfully.
  • likewise, third spec (second nested spec), it's required verylonginitialization , thirdverylonginitialization have been executed sequentially, , completed successfully.

this works nice far.

however, there many expectations in first spec, it's impossible write short description it.

so thought splitting first spec several specs few expectations per spec. make easy write meaningful, short spec descriptions.

however, slows down complete test execution, since verylonginitialization has executed each spec.

so thought putting verylonginitialization beforeall block instead of beforeeach. execute verylonginitialization once, , run specs, thereby speeding overall test execution.

however, means verylonginitialization run once @ all. means third spec run after sequence

verylonginitialization() secondverylonginitialization() thirdverylonginitialization() 

which incorrect. secondverylonginitialization should not have run before third specs.

i hope see our dilemma. is there better approach scenario?

what see way of grouping specs together, example:

it('should this', function () {     ... }).and('should that', function () {     ... }).and('should behave this', function () {     ... }).and('should behave that', function () {     ... }); 

these specs run in single test run, 1 beforeeach of them.

i think work: combine first step specs separate describe , run verylonginitialization before of them. after run verylonginitialization before in second describe , secondverylonginitialization before each. same third step. way you'll have run verylonginitialization 3 times, particular suite requires according description. if worried code duplication verylonginitialization can moved separate function , called multiple times when needed.

describe('base test suite', function () {      // multiple time usage     var verylonginitialization = function (done) {         done();     };      describe('first', function () {          beforeall(function (done) {             verylonginitialization(done);         });          // ...     });      describe('second', function () {          beforeall(function (done) {             verylonginitialization(done);         });          beforeeach(function (done) {             secondverylonginitialization(done);         });          // ...     });      describe('third', function () {          beforeall(function (done) {             verylonginitialization(done);         });          beforeeach(function (done) {             thirdverylonginitialization(done);         });          // ...     });  }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -