1 # Overview of dev_server testing 2 3 ## Introduction 4 5 Catapult has a simple, optionally asynchronous, JavaScript testing framework. 6 The framework is located in `/tracing/base/unittest/`. 7 8 Test files exist in `<filename>_test.html` files where, typically, filename 9 will match the name of the file being tested. The tests sit in the same 10 folder as their respective files. 11 12 ## Test Creation 13 14 The 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 21 tr.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 32 Generally, there is one test suite per file (there is an assumption inside the 33 code that this is true). 34 35 If you add something to the DOM with `appendChild` you should remove it. The 36 exception is if you use `this.addHTMLOutput(element)`. If you use that, then 37 you should be good, the content will get shown if there is an error, 38 otherwise it's hidden. 39 40 The current tests follow the convention that if the test is there just to draw 41 things, to name them with a prefix of instantiate. So, `instantiate`, 42 `instantiate_multiRow`, etc. 43 44 ## Chai 45 46 Catapult 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 51 You'll need to start a dev_server to run the tests 52 ``` 53 $ bin/run_dev_server 54 ``` 55 56 After you start the dev_server, it'll be available at http://localhost:8003. 57 You'll see links to run unit tests for all projects. We'll use the `tracing/` 58 project as an example below. 59 60 ### Running all tests 61 62 ``` 63 http://localhost:8003/tracing/tests.html 64 ``` 65 66 ### Running an individual test suite (such as `ui/foo_test.js`) 67 68 ``` 69 http://localhost:8003/tracing/tests.html?testSuiteName=ui.foo 70 ``` 71 72 ### Running tests named blah 73 74 ``` 75 http://localhost:8003/tracing/tests.html?testFilterString=blah 76 ``` 77 78 ## Options 79 80 If you select the `small format` option on the main test page and reload then 81 the test output will be condensed to a lot smaller, making it easier to see 82 errors without having to scroll the screen. 83