Interview test: Testing the Model/View implementation in your application
Speaker: Stephen Kelly
The Qt Model/View framework provides APIs and an application design structure which encourages a separation of gui components from core functionality. Central to the concept and design is a model, which the developer implements to represent and access application data, and a view, presents the data it to the user in a form suitable to the form factor it is running on. A third central component of the Model/View framework is a proxy model, which can be used to manipulate the data in a ui independent way prior to presenting it to the user in the view. Commonly, a Qt application making use of the Model/View framework will have a custom implemented model and less commonly, one or more custom proxy model.
Real world applications require unit tests both to prevent introducing bugs when writing new features, and to provide a contained, consistent and repeatable use of the code under test for benchmarking and profiling purposes. As a core part of an application, a model implementation will also require its own unit tests. As all model implementations have the same interface, defined by QAbstractItemModel, unit tests for testing a model implementation can share a common pattern. Tests should be written for example to test for items being removed, moved and inserted. The actual implementation of the tests will be specific to the application model however, so a generic test suite for models may not be very useful.
The same is not true of proxy models. Many proxy models are generic and equally usable with different models and in different applications. Much of the test suite can then be generic and reused for testing different proxy models by testing the implementation through the QAbstractProxyModel interface.
This talk is describes the unit test suite developed for the primary model implementation in the Akonadi framework including how to design a model implementation with unit testing in mind. Additionally, the generic proxy model test suite developed in the kde libraries for testing proxy models is described.
Stephen Kelly
Stephen Kelly became a KDE contributor when in 2007 he started maintaining KJots. Since then he has been an Akonadi core developer, implementor of Qt models and proxy models, and author of the Grantlee template system. He writes about this development as much as possible, and has discovered lolcats as the most effective means of communicating with wider audiences. Stephen lives in Berlin, Germany and works at KDAB.