4.2. Writing a Database Class

The database class controls the format in which tests are stored. QMTest's default database class stores each test as an XML file, but you might want to use a format that is particularly well suited to your application domain or to your organization's arrangement of computing resources.

For example, if you were testing a compiler, you might want to represent tests as source files with special embedded comments indicating what errors are expected when compiling the test. You could write a test database class that can read and write tests in that format.

Or, if you wanted to share a single test database with many people in such a way that everyone automatically saw updates to the database, you might want to put all of the tests on a central HTTP server. You could write a test database class that retrieves tests from the server and creates new tests by uploading them to the server.

A test database class is a Python class that is derived from qm.test.database.Database. You must define methods that handle retrieving a test from the database, writing a test to the database, and other related tasks. Read the code for qm.test.database.Database to see what methods need to be overridden.

To use your new database class, create a new test database using the --class (-c) option.