JavaScript Adding test IDs to unit tests for reporting adding unit test to existing project c#,adding unit test

I'm using mocha and trying to build a testing system which reports tests individually. The goal is to have traceability between tests defined in the requirements for the project and unit tests. So, for example, the test 'Must be able to create new widgets' is in the requirements database with id of '43', I want the unit test which tests that criteria to report something like Test 43, Must be able to create new widgets, pass, and then update the corresponding db entry (another service could be responsible for this).

Can this be done in mocha? The only thing I've found so far is to replace text in the it() function with the test id, and use the json reporter to process the results afterwards (but then I don't get the text for what is being tested, unless I combine them and do some kind of parsing). Note: not all tests would have an id.

Here's an example of the kind of functionality I'm hoping for

describe("Widget" function() {
  it("should allow creation of widgets", function() {
    this.id = 43;
    result = widget.create();
    expect.result.to.exist;
  });
});

And then either a hook, like

afterEach(function(test) {
  if (test.hasOwnProperty('id')) {
    report(test.result);
  }
});

Or a custom reporter, or an adapter of some sort.

runner.on('test end', function(test) {
  console.log(test.id); //doesn't exist, but i want it to
  report(test);
});
Answer:1

This depends on your assertion library. With Chai, you havethe optional field for text.

assert.should.exist(result, 'expect Result to exist (Id 43)');

With Jasmine, you can add the test reference to your it():

describe("Widget" function() {
  it("should allow creation of widgets (Id 43)", function() {

To use the Mocha custom reporters you could try to define one in your test suite.

module.exports = MyReporter;

function MyReporter(runner) {
  var passes = 0;
  var failures = 0;

  runner.on('pass', function(test){
    passes++;
    console.log('pass: %s', test.fullTitle());
  });

  runner.on('fail', function(test, err){
    failures++;
    console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
  });

  runner.on('end', function(){
    console.log('end: %d/%d', passes, passes + failures);
    process.exit(failures);
  });
}

There are really 2 suggestions here. The first is the simplest, and is to simply add your id to the description of the it() and then that will show you what has passed and failed. That would be the quickest way to reach your goal.

However, if you wanted to have the fancier method, and could test to ensure things are set, then you could use the custom reporter, which would allow you to fail a test if the ID was not set.

Answer:2

I have the following jquery selector which I am trying to convert to regular javascript. $("#lelement>*").on("dblclick", function(){ }); what would the equivalent be with regular javascript ? Can ...

I have the following jquery selector which I am trying to convert to regular javascript. $("#lelement>*").on("dblclick", function(){ }); what would the equivalent be with regular javascript ? Can ...

  1. javascript equivalent jquery document ready
  2. javascript equivalent jquery find
  3. javascript equivalent jquery
  4. javascript equivalent of jquery closest
  5. javascript equivalent of jquery load
  6. javascript equivalent of jquery ready
  7. javascript equivalent of jquery append
  8. javascript equivalent of jquery trigger
  9. javascript equivalent of jquery each
  10. javascript equivalent of jquery show
  11. javascript equivalent of jquery text
  12. javascript equivalent of jquery html
  13. javascript equivalent of jquery offset
  14. javascript equivalent of jquery empty
  15. javascript equivalent of jquery animate
  16. javascript equivalent of jquery hide
  17. javascript equivalent of jquery data
  18. javascript equivalent of jquery selector
  19. javascript equivalent of jquery parents
  20. javascript equivalent of jquery click

I have 5 boxes and an array of items. How do I display 5 items in 5 boxes, randomly selected without repetition? Is it a problem with: ptags[index].textContent = item[0].label; that it is not ...

I have 5 boxes and an array of items. How do I display 5 items in 5 boxes, randomly selected without repetition? Is it a problem with: ptags[index].textContent = item[0].label; that it is not ...

Often in the interview questions it is heard that Why one should use redux form in the ReactJs instead of simple form. which extra ordinary facilities it provides to the developer ? Then what should ...

Often in the interview questions it is heard that Why one should use redux form in the ReactJs instead of simple form. which extra ordinary facilities it provides to the developer ? Then what should ...

  1. redux form simple example
  2. redux form simple
  3. react redux simple form example
  4. react redux simple form

I am trying to use phantomjs to automate the process of login into facebook. The issue is that facebook uses js codes to set cookies before the login form is submitted. Clicking on the email input box ...

I am trying to use phantomjs to automate the process of login into facebook. The issue is that facebook uses js codes to set cookies before the login form is submitted. Clicking on the email input box ...

  1. phantomjs read cookies