Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups.
Summary: TestObjectFactory(ies) for Koha objects. Enable easy Test object creation fro...
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Olli-Antti Kivilahti
QA Contact: Galen Charlton
URL:
Keywords:
Depends on: 14539 14616
Blocks: 10744 14536 14698
  Show dependency treegraph
 
Reported: 2015-03-25 13:56 UTC by Olli-Antti Kivilahti
Modified: 2023-07-28 22:30 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Large patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (38.72 KB, patch)
2015-03-25 13:57 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (38.79 KB, patch)
2015-06-10 13:54 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (42.86 KB, patch)
2015-06-10 13:56 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - Cucumber tests. (64.96 KB, patch)
2015-06-10 14:03 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (49.14 KB, patch)
2015-07-16 12:36 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (49.14 KB, patch)
2015-07-22 11:23 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups. (49.14 KB, patch)
2015-07-24 13:59 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation/deletion from HASHes. (48.65 KB, patch)
2015-07-31 10:33 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - (follow-up) Add SystemPreferenceFactory (TestObjectFactory) (8.44 KB, patch)
2015-08-12 12:10 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation/deletion from HASHes. (101.56 KB, patch)
2015-08-17 11:59 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactoreis squashables (37.76 KB, patch)
2015-08-31 11:03 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.64 KB, patch)
2015-09-01 09:50 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.69 KB, patch)
2015-09-01 14:20 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.65 KB, patch)
2015-09-01 14:48 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactoreis squashables (37.77 KB, patch)
2015-09-07 10:51 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.27 KB, patch)
2015-09-15 10:08 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.27 KB, patch)
2015-09-15 15:18 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue (8.47 KB, patch)
2015-09-16 14:22 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Holds test factory for v3.16 (15.40 KB, patch)
2015-11-02 18:27 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Holds test factory for v3.16 (15.49 KB, patch)
2016-01-25 08:42 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906 (follow-up) - New TestObjectFactory for creating fines into accountlines (5.81 KB, patch)
2016-01-25 13:50 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation/deletion from HASHes. (181.91 KB, patch)
2017-05-08 14:33 UTC, Lari Taskula
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Olli-Antti Kivilahti 2015-03-25 13:56:27 UTC

    
Comment 1 Olli-Antti Kivilahti 2015-03-25 13:57:42 UTC Comment hidden (obsolete)
Comment 2 Olli-Antti Kivilahti 2015-06-10 13:54:24 UTC Comment hidden (obsolete)
Comment 3 Olli-Antti Kivilahti 2015-06-10 13:56:15 UTC Comment hidden (obsolete)
Comment 4 Olli-Antti Kivilahti 2015-06-10 14:03:55 UTC Comment hidden (obsolete)
Comment 5 Olli-Antti Kivilahti 2015-07-16 12:36:13 UTC Comment hidden (obsolete)
Comment 6 Olli-Antti Kivilahti 2015-07-22 11:23:57 UTC Comment hidden (obsolete)
Comment 7 Zeno Tajoli 2015-07-24 10:09:12 UTC
Hi Olli,

If I try to see the tree of your bugs I see this the first bug to sent master to fix the others.

This is your bugs tree for authentication rewrite:
https://trello.com/b/o3uAES9s

Why is in discussion ?
Comment 8 Olli-Antti Kivilahti 2015-07-24 12:41:47 UTC
(In reply to Zeno Tajoli from comment #7)
> Hi Olli,
> 
> Why is in discussion ?

Originally I made these factories to work best with Cucumber tests, and those have their own stashing and tearDown-mechanisms. Back then I didn't think far enough and those things have been dealt in the Cucumber framework.
So all the other ObjectFactories, sans the BorrowerFactory are of the old model.

I refactored Borrowerfactory to include the features from Cucumber-framework (multi-level stashing) but haven't done that for the rest of the ObjectFactories.
So basically If one was to refactor this commit into something with only the BorrowerFactory and the parent ObjectFactory, this would be ok.

I have tests and documentation to do for the REST API framework, so I can take a look at this after that, but the separation is a very easy task and a good exercise in getting to know the simplicity of these Factories.

There are other bugs to test for the big authentication rewrite, if you feel like waiting for me to properly refactor this feature.
I have built Bug 14540 to be stand-alone testable (with all dependencies), but most of these dependant bugs don't make much sense to test alone (since they do not have the necessary context to prove their usefulness.
You can still safely apply this bug, since the non-refactored factories don't hinder testing the whole rewrite or interfere with Koha in any way.
Comment 9 Olli-Antti Kivilahti 2015-07-24 13:59:49 UTC Comment hidden (obsolete)
Comment 10 Olli-Antti Kivilahti 2015-07-31 10:33:04 UTC Comment hidden (obsolete)
Comment 11 Lari Taskula 2015-08-12 12:10:39 UTC Comment hidden (obsolete)
Comment 12 Olli-Antti Kivilahti 2015-08-17 11:59:50 UTC
Created attachment 41531 [details] [review]
Bug 13906 - TestObjectFactory(ies) for Koha objects. Enable easy Test object creation/deletion from HASHes.
Comment 13 Olli-Antti Kivilahti 2015-08-31 11:03:29 UTC Comment hidden (obsolete)
Comment 14 Lari Taskula 2015-09-01 09:50:03 UTC Comment hidden (obsolete)
Comment 15 Lari Taskula 2015-09-01 14:20:06 UTC Comment hidden (obsolete)
Comment 16 Lari Taskula 2015-09-01 14:48:36 UTC Comment hidden (obsolete)
Comment 17 Lari Taskula 2015-09-07 10:51:57 UTC
Created attachment 42430 [details] [review]
Bug 13906 - TestObjectFactoreis squashables

Fixed File::Fu::File version from PerlDependencies, 0.08 => 0.0.8
Comment 18 Lari Taskula 2015-09-15 10:08:41 UTC Comment hidden (obsolete)
Comment 19 Lari Taskula 2015-09-15 15:18:24 UTC Comment hidden (obsolete)
Comment 20 Lari Taskula 2015-09-16 14:22:35 UTC
Created attachment 42602 [details] [review]
Bug 13906: (follow-up) - MessageQueueFactory for adding messages to message_queue
Comment 21 Olli-Antti Kivilahti 2015-11-02 18:27:29 UTC Comment hidden (obsolete)
Comment 22 Mark Tompsett 2016-01-04 14:56:30 UTC
*ping* Is this moving forward?
Comment 23 Lari Taskula 2016-01-25 08:42:29 UTC
Created attachment 47244 [details] [review]
Bug 13906 - TestObjectFactory(ies) for Koha objects. Holds test factory for v3.16

Fixes a conflict.
Comment 24 Lari Taskula 2016-01-25 13:50:36 UTC
Created attachment 47253 [details] [review]
Bug 13906 (follow-up) - New TestObjectFactory for creating fines into accountlines

Adds FinesFactory that creates new fines into accountlines.
Comment 25 Olli-Antti Kivilahti 2016-02-08 14:11:44 UTC
(In reply to M. Tompsett from comment #22)
> *ping* Is this moving forward?

Don't know about the Koha-community, but we are constantly improving this feature and it works really well in practice (albeit a bit slowly).

All our web-testing scripts are based on this feature and together with the Permission system rewrite
We have code to rapidly deploy and receive a bunch of serials as well, but we haven't shared it yet. Also this code is for Koha 3.16.

This all is aimed to enable doing web-testing in Koha in an effortless way.
Bug 14536 - PageObject-pattern base implementation

We are targeting to migrate to a "possibly" rolling update cycle with the Koha-community versions this summer.
And these modern testing features hopefully will help us gain confidence in our codebase and enable following the community branches in semi-real time.

Time will tell.
Comment 26 Lari Taskula 2017-05-08 14:33:52 UTC
Created attachment 63244 [details] [review]
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);
}
Comment 27 Josef Moravec 2019-01-18 09:09:16 UTC
Could builder->build_object cover this case?
Comment 28 Martin Renvoize 2019-05-14 16:25:59 UTC
(In reply to Josef Moravec from comment #27)
> Could builder->build_object cover this case?

I think you're right.. this can probably be closed as a duplicate at this point?
Comment 29 Katrin Fischer 2023-07-28 22:30:39 UTC
(In reply to Martin Renvoize from comment #28)
> (In reply to Josef Moravec from comment #27)
> > Could builder->build_object cover this case?
> 
> I think you're right.. this can probably be closed as a duplicate at this
> point?

I'll close it.