-
Notifications
You must be signed in to change notification settings - Fork 84
Testing
Trace viewer has a simple, optionally asynchronous, testing framework.
The bulk of the framework exists in tvcm/unittest.html
with the assertions
in tvcm/unittest/assertions.html
.
Test files exist in <filename>_test.html
files where, typically, filename
will match the name of the file being tested. The tests sit in the same
folder as their respective files.
The general structure of tests is (assuming a file of ui/foo_test.html):
<link rel="import" href="/ui/foo.html">
<script>
'use strict';
tvcm.unittest.testSuite(function() {
test('instantiate', function() {
var myFoo = ui.Foo();
this.addHTMLOutput(myFoo);
});
test('somethingElse', function() {
});
});
Generally, there is one test suite per file (there is an assumption inside the code that this is true).
If you add something to the DOM with appendChild
you should remove it. The
exception is if you use this.addHTMLOutput(element)
. If you use that, then
you should be good, the content will get shown if there is an error,
otherwise it's hidden.
The current tests follow the convention that if the test is there just to draw
things, to name them with a prefix of instantiate. So, instantiate
,
instantiate_multiRow
, etc.
Trace viewer is in the process of switching over to Chai for assertions. We are using Chai's TDD assert
style which is similar in philosophy to TVCM assertions but provides a different API.
Chai asserts are now enabled globally, so that when you type assert
inside of a test you are actually using Chai's assert. We are working on converting existing tests in this way.
localhost:8003/tests.html
localhost:8003/tests.html?testSuiteName=ui.foo
localhost:8003/tests.html?testFilterString=blah
If you select the small format
option on the main test page and reload then
the test output will be condensed to a lot smaller, making it easier to see
errors without having to scroll the screen.