[Koha-bugs] [Bug 13906] TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups.

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Jul 16 14:36:13 CEST 2015


http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13906

Olli-Antti Kivilahti <olli-antti.kivilahti at jns.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #40072|0                           |1
        is obsolete|                            |

--- Comment #5 from Olli-Antti Kivilahti <olli-antti.kivilahti at jns.fi> ---
Created attachment 41021
  -->
http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41021&action=edit
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object
creation from HASHes or from preconfigured test groups.

Doing tests should be easy.
One biggest hindrance in doing tests is the difficulty of doing so in Koha.
We use a lot of hard-coded SQL, which occasionally requires quite a bit of
fiddling to get it right. Satisfying complex object dependency chains is hard.
For example, testing Overdue notice sending, one must create
-letters
-overuderules
-circulationrules
-borrowers
-biblios
-items
-issues (checkouts)
...

Also one must take care to clean up the database modifications afterward to
make
encapsulated tests which don't leak over other tests. This is especially so for
front-end testing.

TestObjectFactories significantly alleviate this pain, by offering
preconfigured
test object groups or enable creating test objects on demand.
They try to recover from errors, like when the previous test crashed and left
testing objects into the DB, preventing adding them again.
Also they store what object they created to 3 different levels of stashes to
facilitate complex test configurations, and they have the dignity to clean-up
the test contexts after testing has happened (if the script doesn't crash)!

USAGE:

use t::db_dependent::TestObjects::Borrowers::BorrowerFactory;

%#Setting up the test context
my $testContext = {};

my $password = '1234';
my $borrowerFactory =
t::db_dependent::TestObjects::Borrowers::BorrowerFactory->new();
my $borrowers = $borrowerFactory->createTestGroup([
            {firstname  => 'Olli-Antti',
             surname    => 'Kivi',
             cardnumber => '1A01',
             branchcode => 'CPL',
             flags      => '1', #superlibrarian, not exactly a very good way of
doing permission testing?
             userid     => 'mini_admin',
             password   => $password,
            },
        ], undef, $testContext);

%#Test context set, starting testing:
eval {
    ... #Run your tests here
};
if ($@) { #Catch all leaking errors and gracefully terminate.
    warn $@;
    tearDown();
    exit 1;
}

%#All tests done, tear down test context
tearDown();
done_testing;

sub tearDown {
   
t::db_dependent::TestObjects::ObjectFactory->tearDownTestContext($testContext);
}

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list