Chapter 35. Testing

lb unit is the unit testing framework of the LogicBlox database. This tool gives developers precise control over transactions, workspace creation, data initialization, etc.

Tests can be grouped into suites. A suite is a set of .lb files. Each suite is stored in a filesystem directory where the name of the directory starts with suite. Each test in the suite is identified by a set of files in the suite directory. A suite can (optionally) have two special scripts: and There are no requirements on the file names of the other .lb files.

For example, a test suite could consist of the following files:

Example 35.1. Sample Test Suite

When given tests, suites, or a directory of suites, lb unit will package each individual test into a Test object consisting of the test file path, its setup file path and teardown file path. These Test objects will be processed individually. The setup, test, and teardown files will be read and placed into standard input to be executed. The commands in the test files will be executed through lb interactive, meanwhile test results will be recorded.

Example 35.2. Individual processing of test objects - - - - - -

If an error occurs in, the test file will be skipped and will be executed. In this way, test workspaces can always be removed. If an error or a failure occurs in the middle of a test file, the remaining commands will be skipped and will be executed.

If and/or cannot be found within the test’s directory, a default can be made if the --defaultFixtures tag is present. The default setup will create a unique workspace using:

create --unique

The default teardown will close and delete the workspace using:

close --destroy

When using the default setup, all tests are executed with an open, but empty workspace. If all tests exercise a certain installed program, you could decide to install the logic in

Example 35.3.  Predicate test is available in all tests

create --unique
addblock 'test(x) -> string(x).'

It is also possible to put the logic in a separate file:

Example 35.4. 

create --unique
addblock --file schema.logic

lb unit runs tests using lb interactive, therefore all commands accepted by the lb command can be used in unit tests.