[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
Mon May 8 16:33:52 CEST 2017


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

Lari Taskula <lari.taskula at jns.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #41531|0                           |1
        is obsolete|                            |
  Attachment #42430|0                           |1
        is obsolete|                            |
  Attachment #42602|0                           |1
        is obsolete|                            |
  Attachment #47244|0                           |1
        is obsolete|                            |
  Attachment #47253|0                           |1
        is obsolete|                            |

--- Comment #26 from Lari Taskula <lari.taskula at jns.fi> ---
Created attachment 63244
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=63244&action=edit
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object
creation/deletion from HASHes.

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.
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)!

UNIT TESTS included!

USAGE:

use t::lib::TestObjects::PatronFactory;

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

my $password = '1234';
my $patronFactory = t::lib::TestObjects::PatronFactory->new();
my $patrons = $patronFactory->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::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext);
}

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


More information about the Koha-bugs mailing list