QStudio - qUnit - Unit testing Framework for Kdb
Note: This page is for showing how to run qUnit tests within QStudio
for details on the qUnit framework itself see the qUnit Testing Framework page.
qUnit is a framework for unit testing q code
It is heavily based on the xUnit/jUnit testing frameworks.
qUnit can be ran from the tools menu, when called it will execute the code in the currently open file and run all tests contained within.
Running Example Tests
To run some example unit tests:
- Goto "Help Menu"->"open qunit example .q", this will open two q source files (math.q and mathTest.q)
- Select the math.q file and press Ctrl+E to load that onto the current server.
- Select the testMath.q file and press Ctrl+T to run the tests.
This loads the qUnit framework onto the server in the .qunit namespace and executes the tests. - You will receive a table of results like so:
Notice two of the tests failed and their assertion messages are returned to let the developer know what went wrong.
The rightmost columns contain time/memory used during test.
qUnit - Code Structure
From the examples you can see the qUnit framework enforces a specific structure for tests, this encourages best practices and helps other team members quickly understand the code. Tests should be declared in a separate file within the source code directory and within the file, the functions should be in a namespace. For full details on qUnit and how to create tests see the qUnit Framework Guide Page