Examples

janodvarko edited this page Sep 13, 2010 · 1 revision
Clone this wiki locally

###Example 1: Simple test###
Let’s take a look at a simple test page example (example1.html). Notice that fireunit object is automatically injected into the page by Fireunit extension.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
fireunit.ok(true, "Passing test result");
fireunit.ok(false, "Failing test result.");
fireunit.compare("expected data", "expected data", 
    "Passing verification of expected and actual input.");
fireunit.compare("<div><a>expected</a></div>", "<div><a>actual</a></div>", 
    "Failing verification of expected and actual input.");

// Wait for asynchronous operation.
setTimeout(function(){
    // Finish test
    fireunit.testDone();
}, 1000);
</script>
</head>
<body/>
</html>

As soon as the page is loaded in Firefox, open Firebug’s UI and go to the Test tab. Output of this test should be as follows.

Notice that the Actual Result section is switched into view source mode so, the raw HTML is displayed.

###Example 2: Test suite###
If it’s necessary to launch bunch of tests (HTML pages) at once, you can create a test suite (testSuite1.html). See the next example.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
if (fireunit.forceHttp())
{
  fireunit.runTests( 
    "example1.html",
    "example2.html"
  );
}
</script>
</head>
<body>
</body>
</html>

The current version of Fireunit doesn’t allow to specify custom directory (or more directories) from where tests should be loaded. So, all files passed into the runTests method must be located in the same directory as the testSuite.html file. Notice that forceHttp method is used to make sure that local HTTP server is launched in this case and so all files can be loaded through HTTP. As soon as all tests are finished the Test panel should be automatically opened displaying all gathered results.