6926a32fe95a2f8e03e74b08bde30519bc96b1b8
[kivitendo-erp.git] / SL / BackgroundJob / SelfTest / Base.pm
1 package SL::BackgroundJob::SelfTest::Base;
2
3 use strict;
4
5 use Test::Builder;
6
7 use parent qw(Rose::Object);
8
9 use Rose::Object::MakeMethods::Generic (
10   'scalar --get_set_init' => 'tester',
11 );
12
13 sub run {
14   my ($self) = @_;
15   die 'needs to be overwritten';
16 }
17
18 sub todo {
19   0
20 }
21
22 sub skipped {
23   0
24 }
25
26
27 sub init_tester {
28   Test::Builder->new;
29 }
30
31 1;
32
33 __END__
34
35 =encoding utf-8
36
37 =head1 NAME
38
39 SL::BackgroundJob::SelfTests::Base - Base class for background job self tests.
40
41 =head1 SYNOPSIS
42
43   # in self test:
44   use parent qw(SL::BackgroundJob::SelfTests::Base);
45
46   # optionally use a different tester
47   sub init_tester {
48     Test::Deeply->new;
49   }
50
51   # implement interface
52   sub run {
53     my $self = shift;
54
55     $self->tester->plan(tests => 1);
56
57     $self->tester->ok($value_from_database == $expected_value, 'short explanation');
58   }
59
60 =head1 DESCRIPTION
61
62 This is a base class for self tests.
63
64 =head1 INTERFACE
65
66 Your class will inherit L<Rose::Object> so you can use the class building utils
67 from there, and won't need to worry about writing a new constructor.
68
69 Your test will be instanciated and the run method will be invoked. The output
70 of your tester object will be collected and processed.
71
72 =head2 THE TESTER
73
74 =over 4
75
76 =item C<tester>
77
78 =item C<init_tester>
79
80 If you don't bother overriding C<init_tester>, your test will use a
81 L<Test::More> object by default. Any other L<Test::Builder> object will do.
82
83 The TAP output of your builder will be collected and processed for further handling.
84
85 =back
86
87 =head1 ERROR HANDLING
88
89 If a self test module dies, it will be recorded as failed, and the bubbled
90 exception will be used as diagnosis.
91
92 =head1 TODO
93
94 It is currently not possible to indicate if a test skipped (indicating no actual testing was done but it wasn't an error) nor returning a todo status (indicating that the test failed, but that being ok, because it's a todo).
95
96 Stub methods "todo" and "skipped" exist, but are currently not used.
97
98 =head1 AUTHOR
99
100 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
101
102 =cut