-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathtest-file-approach.html
33 lines (28 loc) · 1.6 KB
/
test-file-approach.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title>YUI Test</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssfonts/fonts-min.css">
</head>
<body>
<h2>Test File Approach</h2>
<p>YUI Test was created with the goal of allowing you to write tests in any way you want, allowing you to mimic other testing environments or tools. Even so, there is a general format for test files that works best in YUI Test.</p>
<p>The best way to organize your tests are in standalone JavaScript files. It's generally a good idea to have one test JavaScript file associated with each source JavaScript file. For example, the source file foo.js might have an associated foo_test.js (you might also have the tests in a separate directory).</p>
<p>Each test file should be setup with the following:</p>
<ol>
<li>Creation of test suites and/or test cases for the source.</li>
<li>Add the test suites and/or test cases to <code>YUITest.TestRunner</code>.</li>
</ol>
<p>It's also usually a good idea to wrap the contents of this file in an instantly invoked function to prevent leaking into the global scope. Here's a good general format for a test file:</p>
<pre><code>(function(){
//define local version of YUITest based on what's available.
var YUITest = this.YUITest || require("yuitest");
var testCase = new YUITest.TestCase({
//test case details
});
YUITest.TestRunner.add(testCase);
})();
</code></pre>
<p>The second line is used to allow your tests to be run either in a web browser or in Node.js.</p>
</body>
</html>