The test 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
Database
, which is itself derived from
Extension
. To create a new database class,
you must define methods that read and write tests, resources, and
suites.
The database is also responsible for determining how tests (and other entities stored in the database) are named. Each item stored in the database must have a unique name. For a database that stores files in the filesystem, the name of the file may be a good name. For a database of unit tests for Python module, the name of the module might be a good name for the tests. Choosing the naming convention appropriate requires understanding both the application domain and the way in which the tests will actually be stored.
The database class must have a GetTest
function which retrieves a test from the database. The
test_id
parameter provide the name of the
test. The GetTest
function returns a
TestDescriptor
.
[1] A
TestDescriptor
indicates the test class, and
the arguments to that test class. QMTest uses that information to
instantiate an instance of the test class itself as
appropriate.
The Write
function is the inverse of
GetTest
. The test database is responsible for
storing the Test
provided. The name of test
can be obtained by calling GetId
on the
Test
. When the Remove
function is called the database is responsible for removing the test
named by the id
parameter.
The functions that handle resources are analogous to those
for tests. For exmaple, GetResource
plays the
same role for resources as GetTest
does for
tests.
[1] |
|