b9jTest: Simplifying and enhancing YUI Test

grink on 2008-08-26T23:22:55

YUI Test is a great tool for javascript testing, but it has a couple of small issues:

  • Setting up the HTML document requires many different .js and .css assets
  • The actual javascript code to set up the test environment is not trivial (setting up the TestRunner, setting up the TestLogger, etc.)
  • A failed assertion will abort the test function immediately, preventing later tests from running

b9jTest addresses the problems above by:

  • Bundling all the required .js and .css assets into just two separate files
  • Providing some boilerplate javascript so you can jump right into testing without a lot of setup

An example b9jTest document:

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>b9jTest example</title>
<link rel="stylesheet" type="text/css"
    href="http://appengine.bravo9.com/b9j/b9jTest.css">
<script type="text/javascript"
    src="http://appengine.bravo9.com/b9j/b9jTest.js"></script>
</head>
<body class="yui-skin-sam">
<div id="testLogger"></div>
<script type="text/javascript">

    b9jTest(function(test) {
        test.areEqual("xyzzy", "xyzzy");
        test.areEqual("apple", "apple");
        test.areEqual("banana", "banana");
    });  

</script>
</body>

b9jTest() is a global function that accepts a function that is called with a testing object. The testing object provides access to the standard YUI assertions and more.

Documentation:

http://appengine.bravo9.com/b9j/documentation/b9jTest.html

Download:

b9jTest.js
b9jTest.css
b9jTest: Simplifying and enhancing YUI Test