Unit Testing

From CommonJS Spec Wiki
Jump to: navigation, search

STATUS: 1.0 RATIFIED, AMENDMENT PROPOSALS PENDING

Unit testing

Automated tests are an important part of software development today. Providing a standard test library will help encourage more people to write more tests. Additionally, the API specification will likely be written in the form of tests, so this component will be needed by the CommonJS project itself.

Testing involves both an API for easily defining tests and running assertions, plus a tool (or tools) for locating and running the tests.

Specifications and Proposals

Known spec bugs in version 1.0:

  • Not self-consistent:
    assert.equal(4,new Number(4));
    assert.deepEqual(4, new Number(4));
  • Not self-consistent:
    assert.equal(/a/, /a/g);
    assert.deepEqual(/a/, /a/g);
  • 7.4 talks about checking prototype properties, not the internal [[Prototype]] itself (__proto__ or Object.getPrototypeOf)
  • Does not handle string equivalence, specifically that strings in deep equivalence calls must be identical, not equal after coercion.
  • assert.throws has to be written assert['throws'] in some implementations to get around protected keywords or JSLint
  • There's a call for "assert.equal" to either be strict or "fixed" for some value of correctness for equality comparison. [1]
  • The NodeJS mailing list calls for "assert.ifError", "assert.noError", or "assert.notOk" [2]

Prior Art

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox