Hi! Please consider following me on twitter: @hanekomu.
2009年03月19日
Pluggable test classes
Ovid has written a series of interesting articles on Test::Class on the "Modern Perl Books" blog. Read them:
- Organizing Test Suites with Test::Class
- Reusing Test Code with Test::Class
- Making Your Testing Life Easier
- Using Test Control Methods with Test::Class
In my work project — we are developing the software for the .at domain name registry — we maintain several module distributions. There is a core registry distribution and an .at-specific registry distribution that inherits from the core. The reason for doing it this way is that our software seems to be quite successful and we are doing registries for other countries as well.
When running tests for the .at registry, we want to run tests that are defined in the core registry as well, to make sure that we haven't broken any core functionality by inheriting.
There is Test::Class::Load to load test classes automatically,
but it only takes directory paths. What we want is to specify package
namespaces. So I've thought about using Test::Class together with
Module::Pluggable.
Our core test classes look something like this:
Registry::Test::Foo Registry::Test::Bar Registry::Test::Baz
The .at registry distribution also defines tests:
Registry::NICAT::Test::Frobnule Registry::NICAT::Test::Hoge
Each of them defines tests using the Test attribute provided by
Test::Class. If we want to run all of them, we use this somewhat
simplified program:
use Module::Pluggable search_path => [ qw(Registry:Test Registry::NICAT::Test) ], require => 1; BEGIN { main->plugins } # just load them Test::Class->runtests;
The BEGIN block is necessary so that the plugins, that is to
say, the test classes, are actually loaded. The require => 1
doesn't actually cause the classes to be loaded immediately; it only says that
when we call plugins() the classes should be loaded.
posted at: 13:32 | path: /dev | permalink | 0 comments | 0 trackbacks
Comments are closed for this story.
Trackbacks are closed for this story.