I am a little new to the Devel :: Cover module, but found it very useful, making sure that I don't skip tests.
The problem I am facing is understanding the report from Devel :: Cover. I looked through the documentation, but I canβt understand what I need for testing in order to get 100% coverage.
Change . I must clearly state that I am not saying that I need 100% coverage, because, as many people point out, 100% coverage is a free term, does not mean that my code does not contain errors, and may not always be completely necessary . Since I am new to Devel :: Cover, I am interested to know why my code does not cover 100% in case I miss some important tests.
Here is the result of the cover report:
line err stmt bran cond sub pod time code
...
36 sub connect_database {
37 3 3 1 1126 my $self = shift;
38 3 100 24 if ( !$self->{dsn} ) {
39 1 7 croak 'dsn not supplied - cannot connect';
40 }
41 *** 2 33 21 $self->{dbh} = DBI->connect( $self->{dsn}, q{}, q{} )
42 || croak "$DBI::errstr";
43 1 11 return $self;
44 }
...
line err % l !l&&r !l&&!r expr
----- --- ------ ------ ------ ------ ----
41 *** 33 1 0 0 'DBI'->connect($$self{'dsn'}, '', '') || croak("$DBI::errstr")
And here is an example of my code that checks for this particular line:
my $database = MyModule::Database->new( { dsn => 'Invalid DSN' });
throws_ok( sub { $database->connect_database() },
qr/Can't connect to data source/,
'Test connection exception (invalid dsn)' );
This test passes - the connection throws an error and runs my throws_ok test.
I have several tests that verify successful communication, so I think I have 33% coverage, but if I read it correctly, the cover thinks that I am not testing part of the "|| croak" expression. I thought I was with the throws_ok test, but obviously something is missing.
Does anyone have any tips on how I can successfully test the DBI-> trunk?
Thank!
Edit:
HTML , , # 41 . , , . , ββ , .
:
LINE
41
- , . , , , - , .
!