Hide successful tests in QUnit

Jun 3, 2010 · Follow on Twitter and Mastodon javascripttesting

I am using QUnit as TDD framework for my JavaScript development. It’s not as nice as NUnit is for .NET or SimpleTest for PHP, but it’s really easy to get started with.

However, QUnit lists all tests after a run, not just the failing ones. With just a few tests, it looks like this:

QUnit - Full test report

As you can see, QUnit lists all executed tests by default, even the ones that is successfully executed.

This report only includes 14 tests. Imagine having a hundred tests - it would become unmanagable. I’d prefer to only see failing tests by default.

To fix this, I devided to hack jQuery a bit (applies to jQuery 1.4.2):

  • Open qunit.js.
  • Find the block that begins with var li = document.createElement("li");.
  • Wrap the entire block in if (bad) { ... }.

This makes QUnit only append “bad” tests to the list, which makes the result look like this:

QUnit - Compact test result presentation

If you know of a built-in way of making QUnit behave like this, please leave a comment below.

Discussions

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon..

Follow for more

If you found this interesting, follow the Twitter and Mastodon accounts for more content like this, and to be notified when new content is published.