Test.Unit.Runner

Unit Testing > Test.Unit.Runner

Introduction

Test.Unit.Runner is a utility class for writing unit test cases with an easy to use syntax.

Syntax


new Test.Unit.Runner(functions [, options] );

The functions and options parameters are both {key: value} collections.

Examples

Using Test.Unit.Runner requires you to use a specific XHTML page template, that looks as follows:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Page title</title>
  <script src="path/to/prototype.js" type="text/javascript"></script>
  <script src="path/to/util.js" type="text/javascript"></script>
  <script src="path/to/unittest.js" type="text/javascript"></script>
  <!-- other JavaScript includes -->
  <link rel="stylesheet" href="path/to/test.css" type="text/css" />
</head>
<body>

<!-- Log output -->
<div id="testlog"> </div>

<!-- here go any elements you do the testing on -->

<!-- Tests -->
<script type="text/javascript" language="javascript">
// <![CDATA[
  new Test.Unit.Runner({
    // optional setup function, run before each individual test case
    setup: function() { with(this) {
      // code
    }},
    // optional teardown function, run after each individual test case
    teardown: function() { with(this) {
      // code
    }},

    // test cases follow, each method which starts 
    // with "test" is considered a test case
    testATest: function() { with(this) {
      // code
    }},
    testAnotherTest: function() { with(this) {
      // code
    }}
  }, { options });
// ]]>
</script>
</body>
</html>

Notice how the with(this) { ... } syntax allows for easily calling on methods of the Test.Unit.Testcase class, which includes the assertions, as defined in Test.Unit.Assertions.

More Examples

Probably the best examples of Test.Unit.Runner are the actual tests used by script.aculo.us. Don’t be afraid to dive in to the code! See the test folder in the repository root.

Signature

Methods

initialize: function(testcases [, options])
parseResultsURLQueryParameter: function()
parseTestsQueryParameter: function()
getResult: function()
postResults: function()
runTests: function()

Properties


options: object (This is an object which is a modification of the options object passed into the initialize function
Хотите красиво отдохнуть? Проститутки Москва – лучший отдых для мужчин.

tests: Array of Testcases
currentTest: Number
logger: Test.Unit.Logger