• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Overview of dev_server testing
2
3## Introduction
4
5Catapult has a simple, optionally asynchronous, JavaScript testing framework.
6The framework is located in `/tracing/base/unittest/`.
7
8Test files exist in `<filename>_test.html` files where, typically, filename
9will match the name of the file being tested. The tests sit in the same
10folder as their respective files.
11
12## Test Creation
13
14The general structure of tests is (assuming a file of ui/foo_test.html):
15
16```
17<link rel="import" href="/ui/foo.html">
18<script>
19'use strict';
20
21tr.b.unittest.testSuite(function() {
22  test('instantiate', function() {
23    var myFoo = ui.Foo();
24    this.addHTMLOutput(myFoo);
25  });
26
27  test('somethingElse', function() {
28  });
29});
30```
31
32Generally, there is one test suite per file (there is an assumption inside the
33code that this is true).
34
35If you add something to the DOM with `appendChild` you should remove it. The
36exception is if you use `this.addHTMLOutput(element)`. If you use that, then
37you should be good, the content will get shown if there is an error,
38otherwise it's hidden.
39
40The current tests follow the convention that if the test is there just to draw
41things, to name them with a prefix of instantiate. So, `instantiate`,
42`instantiate_multiRow`, etc.
43
44## Chai
45
46Catapult uses [Chai](http://chaijs.com) for assertions. We are using Chai's
47[TDD `assert` style](http://chaijs.com/api/assert/).
48
49## Execution
50
51You'll need to start a dev_server to run the tests
52```
53$ bin/run_dev_server
54```
55
56After you start the dev_server, it'll be available at http://localhost:8003.
57You'll see links to run unit tests for all projects. We'll use the `tracing/`
58project as an example below.
59
60### Running all tests
61
62```
63http://localhost:8003/tracing/tests.html
64```
65
66### Running an individual test suite (such as `ui/foo_test.js`)
67
68```
69http://localhost:8003/tracing/tests.html?testSuiteName=ui.foo
70```
71
72### Running tests named blah
73
74```
75http://localhost:8003/tracing/tests.html?testFilterString=blah
76```
77
78## Options
79
80If you select the `small format` option on the main test page and reload then
81the test output will be condensed to a lot smaller, making it easier to see
82errors without having to scroll the screen.
83