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