qunit.q
Actual test functions should then be named test* and contain assertions.
Tests can either pass/fail/exception. Failure is caused by an assert failing. You have the option of configuring qunit to halt on failed assertions allowing you to step into the code at that point.
- TODO - mocking projections are broken, add test and fix.
- website - http://www.timestored.com/kdb-guides/kdb-regression-unit-tests © TimeStored - Free for non-commercial use. License: Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales (CC BY-NC-SA 2.0 UK)
- author - TimeStored.com
Entity Summary
| Entities | Short Description |
|---|---|
| .qunit.EMPTYAR | |
| .qunit.FAIL | |
| .qunit.actualPath | |
| .qunit.ar | holder for result of \ts speed timing in runTests |
| .qunit.assertAlmostEquals[actual;expected;permittedDifferenceInFloats] | Assert that actual and expected values are almost equal i.e. |
| .qunit.assertAlmostKnown[actual;expectedFilename;msg] | assertKnown for big tables: a table is stored as its summary and compared under knownPrecision, so the golden stays small and a float wobble below the step is not a difference; anything else is saved whole and compared with assertAlmostEquals. |
| .qunit.assertEmpty[actual;msg] | assert that actual is empty i.e. |
| .qunit.assertEquals[actual;expected;msg] | Assert that actual and expected value are equal |
| .qunit.assertError[func;arg;msg] | Assert that executing a given function causes an error to be thrown |
| .qunit.assertFalse[actual;msg] | assert that actual is false |
| .qunit.assertKnown[actual;expectedFilename;msg] | Assert that the expectedFilename in the expectedPath contains a variable that is equal to actual. |
| .qunit.assertKnownRun[func;arg] | |
| .qunit.assertNotEmpty[actual;msg] | assert that actual is NOT empty i.e. |
| .qunit.assertThat[actual;relation;expected;msg] | Assert that the relation between expected and actual value holds |
| .qunit.assertThrows[func;arg;exceptionLike;msg] | Assert that executing a given function causes specific exception to be thrown |
| .qunit.assertTrue[actual;msg] | assert that actual is true |
| .qunit.checkTable[actual;expectedTbl] | |
| .qunit.currentNamespaceBeingTested | |
| .qunit.currentTestBeingTested | |
| .qunit.debug | |
| .qunit.doCheck[checkPassed;failMsg] | If checkPassed is false, set the failFlag and possibly throw an exception. |
| .qunit.expectedPath | exception thrown on assertion fail Controls where known expected values are loaded from and new results are saved to |
| .qunit.fail[msg] | Make the test fail with given message. |
| .qunit.failFlag | Useful to generate all actual results. |
| .qunit.findFuncs[ns;pattern;logEmpty] | find functions with a certain name pattern within the selected namespace |
| .qunit.formatTable[tbl] | Display a kdb table as HTML, using cssClass column for css class in HTML |
| .qunit.generateReport[runTestsResult;path] | REPORTING FUNCTIONALITY ############ - Work in Progress Generate an HTML report displaying the results of a test run |
| .qunit.getConf[fn] | for fully specified test function in namespace get its config dictionary. |
| .qunit.getKnown[expectedFilename] | Get a known binary file. |
| .qunit.hashCol[s;h] | a failed hash check leaves the two hashes in ar: the column is named by finding the actual one in cols, never by comparing the summaries again |
| .qunit.ignoreAllExceptions | If true then do not run tests protected, i.e. |
| .qunit.isSummary[x] | by shape, so a value handed to assertKnown is only ever taken for a summary when it is one |
| .qunit.knownPrecision | |
| .qunit.l | list of variables that are mocked but were unset beforehand |
| .qunit.lg[x] | stores log entries to allow generating HTML report if required. |
| .qunit.mock[name;val] | |
| .qunit.mocks | holder for result of last assertion |
| .qunit.r | |
| .qunit.removeVar[name] | delete a variable of format `.ns.name whether it's defnined in ns or not |
| .qunit.render[actual] | a summary renders by section - .Q.s of the dict nests its tables unreadably - so a diff reads "count same, gold moved" |
| .qunit.reset[names] | Reset any variables that were mocked |
| .qunit.roundDeep[x] | the hash must forgive a float wherever assertAlmostEquals does: inside lists, dicts and nested tables too |
| .qunit.roundTo[x;y] | the one number assertAlmostKnown works to: the hash rounds floats to this step, the sample is compared within it half-up to step y, staying float: no long overflow past ~9e12. |
| .qunit.run[x] | attempt to run 0-arg function or throw an error |
| .qunit.runInNs[ns;code] | Run a string of code in a given namespace. |
| .qunit.runNsTests[ns] | Run all tests for a single namespace, return table of pass/fails/timings. |
| .qunit.runTest[fn] | protectively evaluate a single test. |
| .qunit.runTests[nsList] | Run all tests in selected namespaces, return table of pass/fails/timings. |
| .qunit.saveActual[actual;expectedFilename;msg] | Write actual under actualPath as the binary a later run is compared to, and beside it the .txt a reviewer reads: the msg lines, then the rendering under a widened console. |
| .qunit.summarise[t] | the golden stored for a table. |
| .qunit.unsetMocks | dictionary from mock names to their original value etc. |
| .qunit.verdict[resultTbl] | One line saying how the run went, for a reader who reads nothing else. |
Entity Details
.qunit.assertAlmostEquals[actual;expected;permittedDifferenceInFloats]
Assert that actual and expected values are almost equal i.e. that floating types 8/9h are within a small specified difference.
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertAlmostKnown[actual;expectedFilename;msg]
assertKnown for big tables: a table is stored as its summary and compared under knownPrecision, so the golden stays small and a float wobble below the step is not a difference; anything else is saved whole and compared with assertAlmostEquals. Same arguments as assertKnown; the .txt beside the actual is by section. Neither the return nor the report row carries the summary: same-keyed dicts down a result column ARE a table, which then cannot join another namespace's results. The row shows a summary's cols table.
| Return: | actual object |
|---|
.qunit.assertEmpty[actual;msg]
assert that actual is empty i.e. count is zero.
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertEquals[actual;expected;msg]
Assert that actual and expected value are equal
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertError[func;arg;msg]
Assert that executing a given function causes an error to be thrown
| Return: | result of running function. |
|---|---|
| Parameters: |
|
.qunit.assertFalse[actual;msg]
assert that actual is false
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertKnown[actual;expectedFilename;msg]
Assert that the expectedFilename in the expectedPath contains a variable that is equal to actual.
| Parameters: |
|
|---|
.qunit.assertNotEmpty[actual;msg]
assert that actual is NOT empty i.e. count is greater than zero.
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertThat[actual;relation;expected;msg]
Assert that the relation between expected and actual value holds
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.assertThrows[func;arg;exceptionLike;msg]
Assert that executing a given function causes specific exception to be thrown
| Parameters: |
|
|---|
.qunit.assertTrue[actual;msg]
assert that actual is true
| Return: | actual object |
|---|---|
| Parameters: |
|
.qunit.fail[msg]
Make the test fail with given message. Useful for placing in code areas that should never be ran or for marking incomplete test code.
.qunit.failFlag
Useful to generate all actual results. i.e. Set 1b, run all tests, copy actual to expected, Set 0b.
.qunit.findFuncs[ns;pattern;logEmpty]
find functions with a certain name pattern within the selected namespace
| Parameters: |
|
|---|
.qunit.generateReport[runTestsResult;path]
REPORTING FUNCTIONALITY ############ - Work in Progress Generate an HTML report displaying the results of a test run
| Parameters: |
|
|---|
.qunit.getKnown[expectedFilename]
Get a known binary file.
| Parameters: |
|
|---|
.qunit.ignoreAllExceptions
If true then do not run tests protected, i.e. break on assertion failures etc.
.qunit.reset[names]
Reset any variables that were mocked
| Return: | the list of variables unmocked. |
|---|---|
| Parameters: |
|
.qunit.roundTo[x;y]
the one number assertAlmostKnown works to: the hash rounds floats to this step, the sample is compared within it half-up to step y, staying float: no long overflow past ~9e12. mod nulls a null or an infinity, so x fills it back
.qunit.runNsTests[ns]
Run all tests for a single namespace, return table of pass/fails/timings.
| Return: | table of results, or empty list if no tests found |
|---|---|
| Parameters: |
|
.qunit.runTest[fn]
protectively evaluate a single test.
| Return: | dictionary of test success/failure, name, result etc. |
|---|
.qunit.runTests[nsList]
Run all tests in selected namespaces, return table of pass/fails/timings.
| Return: | a table containing one row for each test, detailing if it passed/failed. |
|---|---|
| Parameters: |
|
| throws: | nsNoExist If the namespace you selected does not exist. |
.qunit.saveActual[actual;expectedFilename;msg]
Write actual under actualPath as the binary a later run is compared to, and beside it the .txt a reviewer reads: the msg lines, then the rendering under a widened console.
| Return: | the log message: the first msg line, as the .txt carries it |
|---|
.qunit.summarise[t]
the golden stored for a table. sublist keeps a keyed table's keys, and an empty table still pins its schema through typed-empty head and tail
.qunit.verdict[resultTbl]
One line saying how the run went, for a reader who reads nothing else. Carries no timestamp, so two runs of the same suite diff to nothing.
| Return: | string |
|---|---|
| Parameters: |
|