|
I have a base class Foo that inherits from Test::Class and provides a method, action_ok which calls ok 3 times.
Then I have a class called Bar which inherits from Foo.
Bar::test_something calls $self->action_ok() two times.
As a result, Bar::test_something actually does 6 tests. So test_something has to be declared as:
sub test_something : Test(6)
But this is not intuitive. A user shouldn't need to know that action_ok() performs 3 tests.
I tried to make it more intuitive by implementing action_ok() using fail and pass from Test::More.
ie.:
sub action_ok {
my ($self, $function, $args) = @_;
return 'no function passed' unless $function;
my $result = api_call(@_);
defined $result or fail("$function returned ok");
ref $result eq 'HASH' or fail("$function returned proper data structure");
$result->{error} == 0 or fail("$function returned no error");
pass("action ok");
return $result;
}
I guess another way is to use Test::Builder to export an action_ok method.
Thoughts?
|