<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Console</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>Test Console</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<p>
Test Console is a specialized subclass of the Console widget that's pre-configured to display YUI Test output in an attractive, readable log with no extra configuration needed. Just drop it into your test page and run your tests!
</p>
</div>
<h2 id="getting-started">Getting Started</h2>
<p>
To include the source files for Test Console and its dependencies, first load
the YUI seed file if you haven't already loaded it.
</p>
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre>
<p>
Next, create a new YUI instance for your application and populate it with the
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
YUI will automatically load any dependencies required by the modules you
specify.
</p>
<pre class="code prettyprint"><script>
// Create a new YUI instance and populate it with the required modules.
YUI().use('test-console', function (Y) {
// Test Console is available and ready for use. Add implementation
// code here.
});
</script></pre>
<p>
For more information on creating YUI instances and on the
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
documentation for the <a href="../yui/index.html">YUI Global Object</a>.
</p>
<h2 id="using-test-console">Using Test Console</h2>
<p>
First, create some tests using <a href="../test/index.html">YUI Test</a>. Next, create a Test Console instance on your test page and run your tests.
</p>
<pre class="code prettyprint"><div id="log" class="yui3-skin-sam"></div>
<script>
YUI().use('test-console', function (Y) {
// ... set up your test cases here ...
// Render the console inside the #log div, then run the tests.
new Y.Test.Console().render('#log');
Y.Test.Runner.run();
});
</script></pre>
<p>
Test results will automatically be displayed in the test console. By default, only failing tests and the final summary info will be displayed to keep things readable. If you'd like to see an entry for passing tests as well, just click the "pass" checkbox at the bottom of the console.
</p>
<h3 id="category-filters">Category Filters</h3>
<p>
The Test Console supports filtering of the entries it displays. By default, failing tests and a final summary are always displayed, while passing tests and other status information are hidden to avoid clutter.
</p>
<p>
You can change which categories are displayed or hidden by passing a custom configuration for the <code>filters</code> attribute.
</p>
<pre class="code prettyprint">// Show passing tests as well as failing tests by default.
new Y.Test.Console({
filters: {
pass: true,
fail: true
}
}).render();</pre>
<p>
The following entry categories are available.
</p>
<table>
<thead>
<tr>
<th>Category</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>fail</td>
<td><code>true</code></td>
<td>
<p>
A failing test.
</p>
</td>
</tr>
<tr>
<td>info</td>
<td><code>true</code></td>
<td>
<p>
Summary information displayed after all tests have run, such as the total number of passing and failing tests.
</p>
</td>
</tr>
<tr>
<td>pass</td>
<td><code>false</code></td>
<td>
<p>
A passing test.
</p>
</td>
</tr>
<tr>
<td>status</td>
<td><code>false</code></td>
<td>
<p>
Status information displayed after each test case has run. This can be noisy when running a test suite with many test cases, so it's disabled by default.
</p>
</td>
</tr>
</tbody>
</table>
<h2 id="demo">Demo</h2>
<p>
Here's a working example you can play with. Try checking the "pass" checkbox to see passing tests.
</p>
<div id="log" class="yui3-skin-sam">
<style scoped>
#log h4 {
border: none;
margin: default;
padding: default;
text-transform: none;
}
</style>
</div>
<script>
YUI().use('test-console', function (Y) {
var Assert = Y.Assert,
suite;
suite = new Y.Test.Suite('Test Console');
suite.add(new Y.Test.Case({
name: 'General',
'this test should fail with a forced failure': function () {
Assert.fail();
},
'this test should fail with an unexpected error': function () {
throw new Error('OMG!');
},
'this test should pass': function () {
Assert.areEqual(true, true);
},
'this test should also pass': function () {
Assert.areEqual('monkeys', 'monkeys');
}
}));
Y.Test.Runner.add(suite);
new Y.Test.Console().render('#log');
Y.Test.Runner.run();
});
</script>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#using-test-console">Using Test Console</a>
<ul class="toc">
<li>
<a href="#category-filters">Category Filters</a>
</li>
</ul>
</li>
<li>
<a href="#demo">Demo</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/test-console',
name: 'test-console',
title: 'Test Console',
newWindow: '',
auto: false
};
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>